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?