change download file name

This commit is contained in:
Mohamed Nouffer
2021-11-15 17:13:23 +05:30
parent 6168ec9123
commit 4bf95e28a9
9 changed files with 15 additions and 25 deletions

View File

@ -126,22 +126,12 @@ function Index() {
// //link.setAttribute('download', 'file.xls'); //or any other extension
// //document.body.appendChild(link);
// link.click();
const blob = new Blob([response.data], {type: response.data.type});
const url = window.URL.createObjectURL(blob);
const url = window.URL.createObjectURL(new Blob([response.data], { type: 'application/pdf' }));
const link = document.createElement('a');
link.href = url;
const contentDisposition = response.headers['content-disposition'];
let fileName = 'unknown';
if (contentDisposition) {
const fileNameMatch = contentDisposition.match(/filename="(.+)"/);
if (fileNameMatch.length === 2)
fileName = fileNameMatch[1];
}
link.setAttribute('download', fileName);
document.body.appendChild(link);
link.target = '_blank'
link.click();
link.remove();
window.URL.revokeObjectURL(url);
});
}