Create temporary link for download

后端 未结 5 1526
一向
一向 2020-12-08 18:04

I use ASP.NET
I need to give user temporary link for downloading file from server.
It should be a temporary link (page), which is available for a short time (12 hour

5条回答
  •  北海茫月
    2020-12-08 18:45

    http://example.com/download/document.pdf?token=
    

    The part is key here. If you don't want to involve a database, encrypt link creation time, convert it to URL-safe Base64 representation and give user that URL. When it's requested, decrypt token and compare date stored in there with current date and time.

    Alternatively, you can have a separate DownloadTokens table wich will map said tokens (which can be GUIDs) to expiration dates.

提交回复
热议问题