From 0f2b655a17ebd076eee47efbbd2b4e4c35e4e4c3 Mon Sep 17 00:00:00 2001 From: "min.jiang" Date: Wed, 28 Aug 2024 16:41:43 +0800 Subject: [PATCH] update download att --- frontend/src/pages/user/requests/Home.vue | 41 ++++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/frontend/src/pages/user/requests/Home.vue b/frontend/src/pages/user/requests/Home.vue index 9d1807f..0bf0484 100644 --- a/frontend/src/pages/user/requests/Home.vue +++ b/frontend/src/pages/user/requests/Home.vue @@ -278,9 +278,9 @@ export default { this.mnx_backendErrorHandler(error) }) }, - downloadAttachedFile(request_id, document_id) { + downloadAttachedFile(request_id, document_id, file_name) { - window.open(`http://${window.location.host}/api/workspace/request/fetch-attached-file-as-download?request_id=${request_id}&document_id=${document_id}`) + // window.open(`http://${window.location.host}/api/workspace/request/fetch-attached-file-as-download?request_id=${request_id}&document_id=${document_id}`) // const link = document.createElement('a') // link.href = `${window.location.host}/api/workspace/request/fetch-attached-file-as-download?request_id=${request_id}&document_id=${document_id}` @@ -290,26 +290,27 @@ export default { // link.click() // document.body.removeChild(link) - // WorksapceApi.fetchAttachedFileAsDownload(request_id, document_id) - // .then((response) => { - // // create file link in browser's memory - // const href = URL.createObjectURL(response.data) + WorksapceApi.fetchAttachedFileAsDownload(request_id, document_id) + .then((response) => { + console.log('resposne', response) + // create file link in browser's memory + // const href = URL.createObjectURL(response.data) - // // create "a" HTML element with href to file & click - // const link = document.createElement('a') - // link.href = href - // link.setAttribute('download', 'file.pdf') //or any other extension - // link.setAttribute('_') - // document.body.appendChild(link) - // link.click() + // create "a" HTML element with href to file & click + const link = document.createElement('a') + link.href = response.data.download_url + link.download = file_name + link.target = '_blank' + document.body.appendChild(link) + link.click() - // // clean up "a" element & remove ObjectURL - // document.body.removeChild(link) - // URL.revokeObjectURL(href) //TODO: navigate to the preview page - // }) - // .catch((error) => { - // this.mnx_backendErrorHandler(error) - // }) + // clean up "a" element & remove ObjectURL + document.body.removeChild(link) + // URL.revokeObjectURL(href) //TODO: navigate to the preview page + }) + .catch((error) => { + this.mnx_backendErrorHandler(error) + }) } } }