Ability to cancel uploading progress via x button

This commit is contained in:
Peter Papp
2020-11-22 09:42:44 +01:00
parent 4e5afa4747
commit 16ab540298
4 changed files with 97 additions and 4 deletions

View File

@@ -111,8 +111,13 @@ const actions = {
? '/api/upload/public/' + router.currentRoute.params.token
: '/api/upload'
// Create cancel token for axios cancelation
const CancelToken = axios.CancelToken;
const source = CancelToken.source();
axios
.post(route, form, {
cancelToken: source.token,
headers: {
'Content-Type': 'application/octet-stream'
},
@@ -174,6 +179,15 @@ const actions = {
// Reset uploader
commit('UPDATE_FILE_COUNT_PROGRESS', undefined)
})
// Cancel the upload request
events.$on('cancel-upload', () => {
source.cancel();
// Hide upload progress bar
commit('PROCESSING_FILE', false)
commit('UPDATE_FILE_COUNT_PROGRESS', undefined)
})
})
},
restoreItem: ({commit, getters}, item) => {