Last active
January 23, 2019 11:55
-
-
Save chaman-1/381f0114f4d77c3cd875faffdf566d97 to your computer and use it in GitHub Desktop.
How to upload multiple files without starting their upload parallely, I want to implement synchronous upload, when one file gets uploaded the next file starts uploading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file: FileList; //populated on filechange | |
uploadURI: Array < String >; //populated after filechange | |
public Tus() { | |
if (this.file.length > 0 && this.uploadURI.length > 0) { | |
this.uploadService.tusUpload(this.file, this.uploadURI); | |
} | |
} else { | |
alert('file length error'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as tus from 'tus-js-client'; | |
tusUpload(file: FileList, uploadLink: Array < String > ) { | |
for (let i = 0; i < file.length; i++) { | |
const upload = new tus.Upload(file.item(i), { | |
uploadUrl: uploadLink[i], | |
retryDelays: [0, 1000, 3000, 5000], | |
onError: function(error) { | |
console.log("Failed because: " + error) | |
}, | |
onProgress: function(bytesUploaded, bytesTotal) { | |
let percentage = (bytesUploaded / bytesTotal * 100).toFixed(2) | |
console.log(bytesUploaded, bytesTotal, percentage + "%") | |
}, | |
onSuccess: function() { | |
console.log("Download %s from %s", upload.file.name, upload.url) | |
} | |
}) | |
upload.start() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment