diff --git a/src/api/attachment.js b/src/api/attachment.js index 5c1f9e234..661178156 100644 --- a/src/api/attachment.js +++ b/src/api/attachment.js @@ -1,3 +1,4 @@ +import axios from 'axios' import service from '@/utils/service' const baseUrl = '/admin/api/attachments' @@ -26,4 +27,22 @@ attachmentApi.delete = attachmentId => { }) } +attachmentApi.CancelToken = axios.CancelToken +attachmentApi.isCancel = axios.isCancel + +attachmentApi.upload = (formData, uploadProgress, cancelToken) => { + return service( + { + url: `${baseUrl}/upload`, + timeout: 8640000, // 24 hours + data: formData, // form data + onUploadProgress: uploadProgress, + method: 'post' + }, + { + cancelToken: cancelToken + } + ) +} + export default attachmentApi diff --git a/src/views/attachment/AttachmentList.vue b/src/views/attachment/AttachmentList.vue index a97eb09de..b4396c8b1 100644 --- a/src/views/attachment/AttachmentList.vue +++ b/src/views/attachment/AttachmentList.vue @@ -35,7 +35,8 @@

@@ -217,6 +218,28 @@ export default { }, onChildClose() { this.drawerVisible = false + }, + handleUpload(option) { + this.$log.debug('Uploading option', option) + const CancelToken = attachmentApi.CancelToken + const source = CancelToken.source() + + const data = new FormData() + data.append('file', option.file) + attachmentApi + .upload(data, source.token, option.onProgress) + .then(response => { + option.onSuccess(response, option.file) + }) + .catch(error => { + option.onError(error, error.response) + }) + + return { + abort: () => { + source.cancel('Upload operation canceled by the user.') + } + } } } } diff --git a/src/views/post/PostEdit.vue b/src/views/post/PostEdit.vue index 374e24f7a..fdd4dcb2e 100644 --- a/src/views/post/PostEdit.vue +++ b/src/views/post/PostEdit.vue @@ -124,7 +124,12 @@ > -

+