mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 06:59:09 +00:00
get name from header
- attempt getting name from header. will depend on security policies
This commit is contained in:
@@ -7,10 +7,21 @@ export const downloadEvents = async () => {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
responseType: 'blob', // important
|
responseType: 'blob', // important
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
|
let headerLine = response.headers['Content-Disposition'];
|
||||||
|
console.log(response);
|
||||||
|
let filename = 'events.json';
|
||||||
|
|
||||||
|
// try and get the filename from the response
|
||||||
|
if (headerLine != null) {
|
||||||
|
let startFileNameIndex = headerLine.indexOf('"') + 1;
|
||||||
|
let endFileNameIndex = headerLine.lastIndexOf('"');
|
||||||
|
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
|
||||||
|
}
|
||||||
|
|
||||||
const url = window.URL.createObjectURL(new Blob([response.data]));
|
const url = window.URL.createObjectURL(new Blob([response.data]));
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.setAttribute('download', 'events.json');
|
link.setAttribute('download', filename);
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.click();
|
link.click();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user