allow multiple files upload in single request

This commit is contained in:
Dany LE 2021-11-21 19:19:09 +01:00
parent 66e96cc0db
commit b3d38ccb05
2 changed files with 20 additions and 30 deletions

Binary file not shown.

View File

@ -1216,13 +1216,13 @@ namespace OS {
o.on("change", function () { o.on("change", function () {
const files = (o[0] as HTMLInputElement).files; const files = (o[0] as HTMLInputElement).files;
const n_files = files.length; const n_files = files.length;
const tasks = [];
if (n_files > 0) if (n_files > 0)
API.loading(q, p); API.loading(q, p);
Array.from(files).forEach(file => {
const formd = new FormData(); const formd = new FormData();
formd.append("path", d); formd.append("path", d);
formd.append("upload", file); jQuery.each(files, (i, file) => {
formd.append(`upload-${i}`, file);
});
return $.ajax({ return $.ajax({
url: p, url: p,
data: formd, data: formd,
@ -1231,25 +1231,15 @@ namespace OS {
processData: false, processData: false,
}) })
.done(function (data) { .done(function (data) {
tasks.push("OK");
if (tasks.length == n_files)
{
API.loaded(q, p, "OK"); API.loaded(q, p, "OK");
resolve(data); resolve(data);
o.remove();
}
}) })
.fail(function (j, s, e) { .fail(function (j, s, e) {
tasks.push("FAIL");
if (tasks.length == n_files)
{
API.loaded(q, p, "FAIL"); API.loaded(q, p, "FAIL");
o.remove(); o.remove();
}
reject(API.throwe(s)); reject(API.throwe(s));
}); });
}); });
});
return o.trigger("click"); return o.trigger("click");
}); });
} }