Skip to content
Snippets Groups Projects
Commit e6d3156d authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire: Committed by Reiter, Christoph
Browse files

Upload files in serial instead of parallel to not overburden servers (VPU/Middleware/API#40)

parent 32753075
No related branches found
No related tags found
No related merge requests found
......@@ -90,9 +90,17 @@ class VPUFileUpload extends VPULitElement {
this.handleFiles(this.shadowRoot.querySelector('#fileElem').files);
}
handleFiles(files) {
async asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
async handleFiles(files) {
console.log('handleFiles: files.length = ' + files.length);
([...files]).forEach(this.uploadFile.bind(this))
// we need to wait for each upload until we start the next one
this.asyncForEach(files, async (file) => this.uploadFile(file));
}
sendFinishedEvent(response, file) {
......@@ -109,13 +117,13 @@ class VPUFileUpload extends VPULitElement {
});
}
uploadFile(file) {
async uploadFile(file) {
let url = this.url;
let formData = new FormData();
formData.append('file', file);
fetch(url, {
await fetch(url, {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + window.VPUAuthToken,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment