When sending a docx file from the backend using Express, the code looks like this:
module.exports = (req, res) => {
res.status(200).sendFile(__dirname+"/output.docx")
}
To download and save the file as a blob in Angular, the following code snippet is used:
$http({
url: '/api_cv/cv/gen',
method: "PUT",
responseType: 'blob'
}).success(function (data, status, headers, config) {
var blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
var fileName = headers('content-disposition');
saveAs(blob, 'file.docx');
}).error(function (data, status, headers, config) {
console.log('Unable to download the file')
});
It successfully works in Chrome and Firefox. However, when tested in Safari, a new tab opens without downloading the file. In Internet Explorer (tested via Azure RemoteApp on a Mac), an error message stating, "your current security settings do not allow this file to be downloaded" appears.
The SaveAs function used is from https://github.com/eligrey/FileSaver.js/
Is there an alternative method that can work across all modern browsers and IE10+?