3

Suppose I have a controller action method that returns FileResult. Is it possible to detect whether file was actually downloaded completely to the client?

public ActionResult GetFile(int id)
{
    DownloadInfo data = provider.GetInfo(id);
    this.provider.MarkDownloadStart(id);

    return File(Server.MapPath(data.Filename), "application/pdf");
}

I do store information when action is being invoked, but that only means that someone initiated download. It doesn't give me any information on the server whether download completed...

I also set content disposition header so file is supposedly never opened directly in browser but rather browser asks to open/save it. This makes it easier for the client to save the file...

My thinking

I suppose it's not possible to directly detect that download has actually taken place. but is it possible to do it some other way as by somehow:

  1. loading a view that
  2. has an iframe that
  3. requests a file and
  4. the main view supervises download on the client because it has access to iframe so it sees whether file has finished downloading or not.

Even though upper scenario may seem feasible, I don't know how to actually do this supervision. Maybe there's some other - better - way of doing this task.

The main question being

Is it possible to detect on the server that the client finished file downloading completely and not cancelling it in between download?

Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404

2 Answers2

2

You could use cookies. Here's an example. Here are some of the steps involved in the process:

  1. On the client generate some unique id.
  2. Send the request to the download action by passing this unique id.
  3. Use a window.setInterval to query for the presence of a cookie at regular intervals and check its value.
  4. If the cookie is created and its value matches the one of the unique id then download has finished.

And on the server set the cookie value to the unique id once you have finished streaming the file to the response.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • but *finished streaming* can surely happen because user cancelled downloading... So this doesn't really tell me that downloading has actually finished. But **what's more important** I'm not really interested in detecting finished downloads on the client side, but rather on the server... I've updated my question to reflect this fact. – Robert Koritnik May 16 '12 at 11:07
  • You want to detect on the server whether the client has finished or canceled the download? I am afraid that this is not possible. – Darin Dimitrov May 16 '12 at 11:10
  • Well... *not possible* seems to easy to answer ;) but may as well be the only possible and true answer. – Robert Koritnik May 17 '12 at 10:29
-2

Please visit this url

http://odetocode.com/blogs/scott/archive/2010/06/23/checking-client-download-success-with-asp-net-mvc.aspx

hope this helps to you

Nanda
  • 19
  • 3
  • 5
    Note that [link-only answers](http://meta.stackoverflow.com/tags/link-only-answers/info) are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference. – kleopatra Sep 24 '13 at 08:36