So the express docs have a download function in the following form:
res.download(cvUrl, cvName, function (err) {
if (err) {
// ...
} else {
// ...
}
})
I think this would normally trigger the browser to download the file automatically, with the correct filename, as the response headers are correctly set and I'm receiving a file. But I'm handling the download like this:
this.admin.getCv(cvUrl).then(cv => {
const url = window.URL.createObjectURL(new Blob([cv]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'test'); // how can I access the filename here?
document.body.appendChild(link);
link.click();
})
Is it possible to access the filename (cvName) on the frontend? Adding it as a second parameter seemed like the obvious solution, but didn't work. Any hints would be great,
Thanks,
Nick
**Edit:
import JRS from '../api/jrs';
export default class Admin {
getCv (applicantId) {
return JRS.get(`/admin/cvs/${applicantId}`);
}
}
// JRS.js
import axios from 'axios';
export default axios.create({
baseURL: 'http://localhost:8080',
headers: {
'Content-Type': 'application/json',
},
withCredentials: true
});