Skip to content

Commit cc54bdc

Browse files
committed
feat: made every upload file independent
1 parent ae4bbc8 commit cc54bdc

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

public/script.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ fileInput.addEventListener("change", (e) => {
162162
fileNames.push(file.name);
163163
}
164164

165-
uploadFiles(files);
165+
for (const file of files) {
166+
uploadFiles([file]);
167+
}
166168
});
167169

168170
const setTitle = () => {
@@ -237,16 +239,17 @@ const uploadFiles = (files) => {
237239
};
238240

239241
xhr.upload.onprogress = (e) => {
240-
//All files upload together are binded by the same progress. The loop should probably be on the call to this function to track each upload individually.
241-
let sent = e.loaded;
242-
let total = e.total;
243-
console.log("upload progress:", (100 * sent) / total);
244-
245-
for (const file of files) {
246-
let progressbar = file.htmlRow.getElementsByTagName("progress");
247-
progressbar[0].value = ((100 * sent) / total);
248-
}
249-
};
242+
//All files upload together are binded by the same progress. The loop should probably be on the call to this function (uploadFiles) to track each upload individually.
243+
//This will consequently only allow a single file uploaded per request.
244+
let sent = e.loaded;
245+
let total = e.total;
246+
console.log(`upload progress (${files[0].name}):`, (100 * sent) / total);
247+
248+
for (const file of files) {
249+
let progressbar = file.htmlRow.getElementsByTagName("progress");
250+
progressbar[0].value = ((100 * sent) / total);
251+
}
252+
};
250253

251254
xhr.onerror = (e) => {
252255
console.log(e);

0 commit comments

Comments
 (0)