diff --git a/frontend/src/models/DirectoryModel.js b/frontend/src/models/DirectoryModel.js index d0faf2747..d29d4c158 100644 --- a/frontend/src/models/DirectoryModel.js +++ b/frontend/src/models/DirectoryModel.js @@ -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`); diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue index 51f3f3d26..30d92f2ba 100644 --- a/frontend/src/views/Home.vue +++ b/frontend/src/views/Home.vue @@ -295,8 +295,8 @@ export default { this.$refs.uploadMenu.open(event, elem); }, onCancelUpload() { - if (!this.uploadRequest) return; - this.uploadRequest.abort(); + if (!this.uploadRequest || !this.uploadRequest.xhr) return; + this.uploadRequest.xhr.abort(); }, // generic dialog focus handler onDialogShow(focusElementId) {