i am trying:
.post("/getAttachments", (req, res, next) => {
repository.getAttachments(req.body)
.then((attachment) => {
return res.sendFile('https://host.com' + attachment.req.path);
})
.catch(next);
})
///clientService:
function getAttachments(params) {
return $http.post(baseUrl + "/getAttachments", params, {responseType: 'arraybuffer'}).success(function (data) {
let blob = new Blob([data], {type: 'application/vnd.ms-excel'});
saveAs(blob);
});
};
all works for local files only. Please Can you help with it?
res.sendFile
will work only for local files. For remote file you would need something like:
request('https://host.com' + attachment.req.path).pipe(res);
using request
module:
Make sure that you send correct headers and add some error handling.
Another option would be to redirect the user to the correct URL instead of sending it:
res.redirect('https://host.com' + attachment.req.path);
if you want the client to download the file without your server proxying the request in the middle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With