Skip to content

Instantly share code, notes, and snippets.

@chaman-1
Last active January 23, 2019 11:55
Show Gist options
  • Save chaman-1/381f0114f4d77c3cd875faffdf566d97 to your computer and use it in GitHub Desktop.
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
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');
}
}
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