0

I have a nodejs backend and I want to send a file download link to the client such that, the file is directly accessible by the client. The file types are JPEG and PNG. Currently, I am serving these files as data-uri but, due to a change in requirements, I must send a download link in response to the file request and, client can download the file later using that link.

Now the current workflow exposes a path /getAvatar. This path should send a response back to the client with the file link. The file, is stored in /assets/avatars relative to the server root. I know I can express.static middleware to send back static resources. However, the methods I have seen so far, res.send() and res.download() both tries to send the file as attachment rather a link that can be used later to download.

Basically, the behavior is like a regular file sharing site where, once a file is clicked, a link to it is generated which, is used for downloading the file. How can I do this?

Abrar Hossain
  • 2,594
  • 8
  • 29
  • 54
  • https://stackoverflow.com/questions/7288814/download-a-file-from-nodejs-server-using-express – hoangdv May 02 '19 at 05:38
  • in same method pass parameter like {type: 'avatar or URL'} and based on type return the data –  May 02 '19 at 12:11

0 Answers0