Angel Cuenca
Angel Cuenca

Reputation: 1659

Download file from specific server folder using Node JS

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

Answers (1)

Angel Cuenca
Angel Cuenca

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

Related Questions