开发者

How to keep an download url given for a user valid for a minute , once the time is elapsed, the web app should redirect to error page

I want to provide a url to an requested user through email for a download request. The url is valid for a minutes, when user tries to access that url after a minutes the web app should redirect him to another page. what is the best logic to go a开发者_Python百科bout!!.kindly let me know your views.


Create an URL to the resource to download that contains a query string with an encrypted expiration date. Very simple to manage and you don't have to rely on a database.

http://example.com/download.php?aid=jHYgIK7d


  1. Generate a large random string (GUID)

  2. Write this string with the timestamp to a database

  3. Give the user a link to /download?guid=[your guid]

  4. Write a servlet and map it to /download

  5. in your servlet

5.1. Read the GUID from the request parameter

5.2. check the database that the time is still valid

5.3. if yes, read the file from your server and stream it from the servlet to the user (make sure to set the content type correctly)

5.4. update the db-table to indicate that this GUID was already used

5.3' if not, redirect to error page

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜