change download file name
This commit is contained in:
@ -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);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user