This commit is contained in:
@ -66,22 +66,25 @@ export class APIClient {
|
||||
if (args.upProgress) {
|
||||
const res: XMLHttpRequest = await new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.upload.addEventListener("progress", (e) =>
|
||||
{ args.upProgress!(e.loaded / e.total); }
|
||||
);
|
||||
xhr.addEventListener("load", () => { resolve(xhr); });
|
||||
xhr.addEventListener("error", () =>
|
||||
{ reject(new Error("File upload failed")); }
|
||||
);
|
||||
xhr.addEventListener("abort", () =>
|
||||
{ reject(new Error("File upload aborted")); }
|
||||
);
|
||||
xhr.addEventListener("timeout", () =>
|
||||
{ reject(new Error("File upload timeout")); }
|
||||
);
|
||||
xhr.upload.addEventListener("progress", (e) => {
|
||||
args.upProgress!(e.loaded / e.total);
|
||||
});
|
||||
xhr.addEventListener("load", () => {
|
||||
resolve(xhr);
|
||||
});
|
||||
xhr.addEventListener("error", () => {
|
||||
reject(new Error("File upload failed"));
|
||||
});
|
||||
xhr.addEventListener("abort", () => {
|
||||
reject(new Error("File upload aborted"));
|
||||
});
|
||||
xhr.addEventListener("timeout", () => {
|
||||
reject(new Error("File upload timeout"));
|
||||
});
|
||||
xhr.open(args.method, url, true);
|
||||
xhr.withCredentials = true;
|
||||
for (const key in headers) {
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
if (headers.hasOwnProperty(key))
|
||||
xhr.setRequestHeader(key, headers[key]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user