The GiG
The GiG

Reputation: 2611

File Download Callback

I have a page in my site that creates a .doc file and lets the user download it. I want to be able to delete that file from the server after the user has downloaded it.

Is there any way to tell the browser to call a JavaScript callback function I wrote(so I can use ajax and delete the file), or any other way for me to know when to delete the file?

Upvotes: 0

Views: 3653

Answers (2)

hungryMind
hungryMind

Reputation: 6999

After you have streamed your file from server, you can delete them. What you are using at server side. For example in aspx, http://forums.asp.net/p/1204802/2109808.aspx

  private void fileDownload(string fileName, string fileUrl)
    {
        Page.Response.Clear();
        bool success = ResponseFile(Page.Request, Page.Response, fileName, fileUrl, 1024000);
        if (!success)
            Response.Write("Downloading Error!");
        else
       // you can delete here
        Page.Response.End();
    }

Upvotes: 1

iGEL
iGEL

Reputation: 17392

Nope, there isn't. You may pass the file through a server side script (PHP, Rails, etc), which deletes it afterwards or, if your webserver runs with linux or another unix, just delete it after the download has started. On thouse platforms, the file gets deleted for real after the last process closes it's handle, so even if you delete the file while the user still downloads it, the user can continue to do so.

Upvotes: 1

Related Questions