diff --git a/client/src/app/api/ontimeApi.js b/client/src/app/api/ontimeApi.js index fa41a6bcf..4ebc5f73b 100644 --- a/client/src/app/api/ontimeApi.js +++ b/client/src/app/api/ontimeApi.js @@ -7,10 +7,21 @@ export const downloadEvents = async () => { method: 'GET', responseType: 'blob', // important }).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 link = document.createElement('a'); link.href = url; - link.setAttribute('download', 'events.json'); + link.setAttribute('download', filename); document.body.appendChild(link); link.click(); });