change download file name

This commit is contained in:
Mohamed Nouffer
2021-11-16 14:43:56 +05:30
parent 31530b06a6
commit a6e0cc713c
9 changed files with 22 additions and 27 deletions

View File

@ -116,22 +116,17 @@ function Index() {
function downloadReport(url) {
fetch(url)
.then(async response => {
console.log(response);
const filename = response.headers
.get("Content-Disposition")
console.log(filename)
// .split('"')[1];
const text = await response.text();
//console.log(filename)
//console.log(text)
//return { filename, text };
})
.then(responseText => this.download(responseText))
.catch(error => {
//messageNotification("error", error.message);
throw new Error(error.message);
.then(response => {
console.log(response)
const filename = response.headers.get('Content-Disposition').split('filename=')[1];
response.blob().then(blob => {
let url = window.URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
});
});
}
// function downloadReport(url) {