简体   繁体   中英

How to generate a one-time download link in Node.js?

I would like to generate a one-time download link in Node.js and email it to the user so he/she can download it. I would want the link to expire after a while, say one day or one week for example. How can I do this using node.js?

Thanks!

I can download the file using res.download but it sends the file directly to the client and do not generate download link.

This depends on where are you saving the file.

If you just save the file in your own server, then if you save the file in a static folder you can expose the file through your server's link.

This explains it "uploading File to a static folder in the Server" https://www.bezkoder.com/node.js-express-file-upload/

Now, you also want to expire the link. This would be more complicated since now you have to store the timestamp with respect to a link in the database and make the link invalid when the allocated duration passes.

This all is done by amazon s3 so if its possible to use that you should use it instead of implementing everything.

In aws s3, you can store your file and generate signed links that expire after a duration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM