Reputation: 1659
I'm implementing a rest API to download files from specific source into a server, I'm using routing-controllers, but I generate an error, for testing purposes I'm harcoding the locally path of the file that I need to download in the browser.
@Get('/download')
downloadFile(@Res() response: Response) {
response.download(`C:/Attachments/Folder_1/test.pdf`);
}
Error:
Error
at NotFoundError.HttpError [as constructor] (C:\PERSONAL\EA\SAI\SAI-API\sai-api\node_modules\routing-controllers\http-error\HttpError.js:27:23)
Upvotes: 0
Views: 747
Reputation: 1659
It was solved using this implementation:
@Get('/download')
async downloadDocument(@Res() response: Response) {
await promisify<string, void>(response.download.bind(response))(`C:/Attachments/Folder_1/test.pdf`)
return response;
}
Upvotes: 5