filemanager: fix upload cancellation
This commit is contained in:
@@ -67,13 +67,12 @@ export function createDirectoryModel(origin, accessToken, api) {
|
||||
|
||||
return result.body.entries;
|
||||
},
|
||||
async upload(targetDir, file, progressHandler) {
|
||||
upload(targetDir, file, progressHandler) {
|
||||
// file may contain a file name or a file path + file name
|
||||
const relativefilePath = (file.webkitRelativePath ? file.webkitRelativePath : file.name);
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
const req = new Promise(function (resolve, reject) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.addEventListener('load', () => {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
resolve(xhr.response);
|
||||
@@ -101,10 +100,13 @@ export function createDirectoryModel(origin, accessToken, api) {
|
||||
xhr.send(file);
|
||||
});
|
||||
|
||||
const res = await req;
|
||||
// attach for upstream xhr.abort()
|
||||
req.xhr = xhr;
|
||||
|
||||
return req;
|
||||
},
|
||||
async newFile(filePath) {
|
||||
await this.save(filePath, '')
|
||||
await this.save(filePath, '');
|
||||
},
|
||||
async newFolder(folderPath) {
|
||||
await superagent.post(`${origin}/api/v1/${api}/files/${folderPath}?access_token=${accessToken}&directory=true`);
|
||||
|
||||
Reference in New Issue
Block a user