mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-12-27 09:48:21 +01:00
allow multiple files upload in single request
This commit is contained in:
parent
66e96cc0db
commit
b3d38ccb05
Binary file not shown.
@ -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");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user