tags:

views:

105

answers:

4

We're using ASP.NET MVC and our action does this:

  • pull records from DB
  • mark records as downloaded
  • push zipped download to browser

Now the problem comes when the download doesn't complete for some reason - maybe the user clicks "Cancel" or IE pops up that download security bar. I'm wondering if there's an alternative solution.

Could we push the download to the user and then only mark records as downloaded when we're sure they've received the right number of bytes? I have to say that I'm struggling with this one and a solution which is as easy for end users as possible would be fantastic.

+1  A: 

I don't believe there is. If this is necessary you may need to utilize a Silverlight (Or flash) control in conjunction with your application.

Basically the approach with either one would be to open a socket connection to the HTTP url and save it to the appropriate path on the User's drive. Once the download is complete you could have the control generate a hash value from the file and send that back to some ASP page. If the hash value is never submitted or is incorrect you know they didn't finish the file.

Spencer Ruport
The requirement is that it's as hassle-free for the client as possible so Silverlight is out, but Flash is a possibility, I'd be interested in any answers related to that.
colinramsay
Updated answer.
Spencer Ruport
+1  A: 

Rather than simply redirecting the user to the resource that is to be downloaded (there by causing the popup of would you like to download a file) you might try to two things. Push the resource out of a page as a byte array. Once the download has completed redirect the download page to another page. On this page you can then add to your workflow asking if the download went ok or not. Also, if they got this far you could assume (ass-u-me) that it worked. To actually track how far the download got I don't think is doable as you have nothing on the other end monitoring bytes received.

Andrew Siemer
This isn't really an acceptable solution, as one possible problem involves the clients saying they've download records when in fact they have not. I acknowledge this is a problem of process, rather than a technical issue, but if there was a technical solution then that would be ideal for everyone.
colinramsay
+1  A: 

Even checking that all the bytes were sent doesn't really guarantee anything:

  • The user might still cancel the download before saving it, or their browser might crash, etc.
  • The recipient might not be the user. It might be a proxy server with a virus scanner that decides to block the transfer, etc.
Andrew Medico
+1  A: 

There isn't any reliable way to do this without a process running on the client which can verify the transfer completed. Of course, the only process we can reasonably expect the user to already have, or be willing to install, is Flash.

Only Flash 10 supports saving files directly to disk as the user requests. (Previous versions had a "shared object" which was kind of like a very large cookie space more than anything else - not for transferring files but saving reusable application data). Read up here for info on how to interact with the end-user's filesystem via Flash 10.

Essentially there is a method call save() which will push data to a location of the user's choosing. The specific location is hidden from your code; for obvious security reasons, you merely push the file into a black box and Flash handles the rest.

The only real bit of info missing here is how to get your file into the Flash player, but anyone with a little Flash experience should have no trouble figuring that out with a few minutes of research. Without Flash experience you should still have it working in under a day.

Rex M
I think this is going to be the best bet overall, but any other thoughts are still appreciated.
colinramsay
Silverlight can't do it? Only Flash?
Andrei Rinea
@Andrei Silverlight *can* do it, but in the wild we cannot reasonably expect the user to already have (or be willing to install) Silverlight. However, Flash is already installed on some 99% of systems. For a controlled audience, Silverlight may be great. Otherwise it is putting an unnecessarily high barrier to entry for people to use the site ("install this thing before you can do what you actually came here to do").
Rex M