Skip to content Skip to sidebar Skip to footer

Set Cookie Only After File Download Complete.

I have a scenario where I want to tell the user that download is completed and prompt a close button. For this I am using a jquery plugin which monitors a cookie continuously to kn

Solution 1:

you may make another request (with AJAX/jquery) on successCallback (if this is the plugin you're using), pointing to another servlet that set the cookie in the response.

Solution 2:

I did some thing hibride of what RaviH and Marco proposed. I used the Jquery fileDownload Plugin to monitor when the download starts and then changing the visuals accordingly. Then on successCallback event I am start a piece of JS code which continuously polle to the server for the download status.

I achived this by setting a session attribute in the servlet which pushes the file through stream. The session attributes name contains the random string sent with the request, In my case I am sending current Time in milliseconds e.g DOWNLOAD_STATUS_(Random Code).

Again when I am polling I am resending the same Random Code through ajax and get the status. The three status I am using are `STARTED`,`PROGRESS` and `COMPLETE`. 

On browser I show the progress or loading animation while I get the Progress response but when i get the Complete Response I Made appopriate changes to show Download complete.

Hope this help others.

Solution 3:

Cookies are set using set-cookie header in HTTP protocol. This being a header it will not be possible to set the cookie at the end of a request when the download completes. You should find some other way to do this. May be track the download complete on the server and then detect that by polling the server. Other way is using long-polling/comet.

Post a Comment for "Set Cookie Only After File Download Complete."