0

I am new to nodejs/expressjs, and I am building a web app and require file download functionality I have a simple code to allow the client side to download files from the server. The GET call is as follows:

app.get('/FileDownload', function(req, res){
    var sourcePath = /mydrive/pic.png;
    res.download(sourcePath, 'pic.png');
});

Upon clicking download from the frontend, a status of 200 was returned, and using the developer tools I was able to see that the response returned the picture in binary format. However, no files were downloaded to my client.

Network Headers:

Request URL: HOST:PORT/FileDownload

Request Method: GET

Status Code: 200 OK

Response: �PNG

IHDR�I�9usRGB���gAMA���a pHYs���o�d�IDATx^��y�$�u�Y EHKW��յ���$M��@R�(i)�J�̖Z���8=

However, when typing in the get request into the browser directly, the file was able to download. Any advice on how I can make the download prompt appear?

chaooder
  • 1,358
  • 1
  • 17
  • 37
  • Possible duplicate of [Download a file from NodeJS Server using Express](https://stackoverflow.com/questions/7288814/download-a-file-from-nodejs-server-using-express) – DrNio Apr 28 '18 at 16:51
  • You forgot the quotes around the sourcePath string. You're sending a regexp object, not a string. – Rodrigo Leite Apr 28 '18 at 18:19

0 Answers0