Fix Download Blob Pdf

This commit is contained in:
R
2023-02-01 19:35:30 +07:00
parent 75c9781a22
commit 5a0136acf8

View File

@@ -358,15 +358,25 @@ export default function CorporatePlanList() {
const handleDownloadLog = (row: ReturnType<typeof createData>) => {
setLoadingLog(true);
axios.get(`generate-log/${row.id}`)
axios.get(`generate-log/${row.id}`, {
responseType: 'blob'
})
.then((response) => {
const link = document.createElement('a');
link.href = response.data.data.file_url;
link.setAttribute('download', response.data.data.file_name);
document.body.appendChild(link);
link.click();
window.open(URL.createObjectURL(response.data));
// const content = response.headers['content-type'];
// download(response.data, file.file_name, content);
// const link = document.createElement('a');
// console.log(response.data);
// link.href = response.data.data.file_url;
// link.setAttribute('download', response.data.data.file_name);
// document.body.appendChild(link);
// link.click();
setLoadingLog(false);
})
// .then((blobFile) => {
// new File([blobFile], 'asdads.pdf', { type: blobFile.type })
// setLoadingLog(false);
// })
.catch((response) => {
enqueueSnackbar(response.message, {variant: 'error'})
setLoadingLog(false);