mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-11-08 14:08:22 +01:00
fix: upload API only submit a task when files are selected
This commit is contained in:
parent
acd36a7a29
commit
6523fafe91
@ -1306,33 +1306,42 @@ namespace OS {
|
|||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
export function upload(p: string, d: string): Promise<any> {
|
export function upload(p: string, d: string): Promise<any> {
|
||||||
return API.Task(function (resolve, reject) {
|
return new Promise( (resolve, reject) => {
|
||||||
//insert a temporal file selector
|
//insert a temporal file selector
|
||||||
const o =
|
const o =
|
||||||
$("<input>")
|
$("<input>")
|
||||||
.attr("type", "file")
|
.attr("type", "file")
|
||||||
.attr("multiple", "true");
|
.attr("multiple", "true");
|
||||||
o.on("change", function () {
|
o.on("change", async () => {
|
||||||
const files = (o[0] as HTMLInputElement).files;
|
try{
|
||||||
const formd = new FormData();
|
const files = (o[0] as HTMLInputElement).files;
|
||||||
formd.append("path", d);
|
const formd = new FormData();
|
||||||
jQuery.each(files, (i, file) => {
|
formd.append("path", d);
|
||||||
formd.append(`upload-${i}`, file);
|
jQuery.each(files, (i, file) => {
|
||||||
});
|
formd.append(`upload-${i}`, file);
|
||||||
return $.ajax({
|
|
||||||
url: p,
|
|
||||||
data: formd,
|
|
||||||
type: "POST",
|
|
||||||
contentType: false,
|
|
||||||
processData: false,
|
|
||||||
})
|
|
||||||
.done(function (data) {
|
|
||||||
resolve(data);
|
|
||||||
})
|
|
||||||
.fail(function (j, s, e) {
|
|
||||||
o.remove();
|
|
||||||
reject(API.throwe(s));
|
|
||||||
});
|
});
|
||||||
|
const ret = await API.Task((ok, nok) => {
|
||||||
|
$.ajax({
|
||||||
|
url: p,
|
||||||
|
data: formd,
|
||||||
|
type: "POST",
|
||||||
|
contentType: false,
|
||||||
|
processData: false,
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
ok(data);
|
||||||
|
})
|
||||||
|
.fail(function (j, s, e) {
|
||||||
|
//o.remove();
|
||||||
|
nok(API.throwe(s));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
resolve(ret);
|
||||||
|
}
|
||||||
|
catch(e)
|
||||||
|
{
|
||||||
|
reject(__e(e));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return o.trigger("click");
|
return o.trigger("click");
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user