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
Generate a large random string (GUID)
Write this string with the timestamp to a database
Give the user a link to /download?guid=[your guid]
Write a servlet and map it to /download
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
精彩评论