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,38 +1216,28 @@ 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); jQuery.each(files, (i, file) => {
formd.append("upload", file); formd.append(`upload-${i}`, file);
return $.ajax({ });
url: p, return $.ajax({
data: formd, url: p,
type: "POST", data: formd,
contentType: false, type: "POST",
processData: false, contentType: false,
}) processData: false,
.done(function (data) { })
tasks.push("OK"); .done(function (data) {
if (tasks.length == n_files) API.loaded(q, p, "OK");
{ resolve(data);
API.loaded(q, p, "OK"); })
resolve(data); .fail(function (j, s, e) {
o.remove(); API.loaded(q, p, "FAIL");
} o.remove();
}) reject(API.throwe(s));
.fail(function (j, s, e) {
tasks.push("FAIL");
if (tasks.length == n_files)
{
API.loaded(q, p, "FAIL");
o.remove();
}
reject(API.throwe(s));
});
}); });
}); });
return o.trigger("click"); return o.trigger("click");