3

I have this page where a user can upload documents (multiple documents, size limit 10MB each). It is a two step process. Step 1 has the input form. Step 2 is the preview page with a submit button.

How should I handle the scenario where the user closes the browser while on the preview page, without submitting the form? Should I save the files in a temp location after step 1? Is this a decent solution?

And what are the best practices in general for uploading (reasonably) large files?

Thanks.

user471317
  • 1,231
  • 2
  • 22
  • 35

3 Answers3

1

Take a look at this:

http://www.codeproject.com/Articles/68374/Upload-Multiple-Files-in-ASP-NET-using-jQuery

One way or another, you'll probably end up looking at a jQuery/AJAX control to do this.

IrishChieftain
  • 15,108
  • 7
  • 50
  • 91
0

If the user leaves, then let them start over. More than likely they left for a good reason. If there was a crash, leave the responsibility on their end. If you choose to store their data without them submitting this could allow malicious users to exploit your storage.

You can also look into a process called chunking.

For a more in depth discussion on file uploads in mvc3, see this SO post: MVC 3 file upload and model binding

Community
  • 1
  • 1
Travis J
  • 81,153
  • 41
  • 202
  • 273
  • "If the user leaves, then let them start over." - I will have to save the files after step 1, right? – user471317 Apr 06 '12 at 00:03
  • @user471317 - You can use the PRG pattern where the files are then placed into `TempData`. If you are saving the files after step 1 then why allow them to preview? Is there a delete functionality involved via a cancel button? Is a flag set once they decide to accept? The reason I ask is that you are going to have to do some auditing to determine how you will remove files which were not committed past step 2. And if the user doesn't have to click accept in step 2, then they will just do step 1 and navigate elsewhere to save time. – Travis J Apr 06 '12 at 00:26
  • "If you are saving the files after step 1 then why allow them to preview?" - I prefer not to save files after step 1. You are suggesting I save the files in TempData after step 1? – user471317 Apr 08 '12 at 21:25
0

You can use a temporary folder to save the files and copy the files to their final location only on submission of the form.

In any case, it would be better to implement a garbage collector. The garbage collector can empty the temporary folder every night. But when using a garbage collector, if you have a way to identify files that were not submitted (for example, if a row is added to a database upon submission), you can put the files in their final location from the beginning, and let the garbage collector remove them every night.

Upload of large files can be done using a JQuery UI plugin such as Uploadify: http://www.uploadify.com/. You should pay attention that it uses flash, which on the one hand is very good for uploading large files, but on the other hand it will prevent your application from supporting Apple machines such as iPad.

Ben
  • 398
  • 2
  • 8