0

Is it possible to upload a file asynchronously to a website using ASP MVC 4?

In my current solution, when the user uploads a file, the post-back checks the number of bytes in the file stream - if it's greater than 8024 bytes, we put an error in TempData and return back to the same page indicating that a file is too large. If it is under 8024, then I create a new Task that will funnel bytes from the FileStream into a new destination file, somewhere on the server.

However, my boss correctly pointed out that at that point it may be too late to warn the user that their file is too large.

We were wondering whether it was possible to check the length of the file on the server side before reading any bytes from the user (and thus without the user having to wait for the file to fully upload before finding out that their file is too large - imagine trying to upload an 8125kb file on a 3MBit connection only to find out that actually the file you gave was 1 byte too large, sorry, try again.

The reason I asked if we could upload a file asynchronously is because this seems very much like asynchronous streaming to me - immediately give a response, regardless of the actual progress of the upload.

We're aware you can use IIS (through the httpHandler attribute in the configuration) to prevent requests over X bytes, but we want to handle error handling ourselves.

Dan
  • 10,282
  • 2
  • 37
  • 64
  • This may help: http://stackoverflow.com/questions/10445861/validating-for-large-files-upon-upload –  Jun 27 '14 at 08:56
  • That's very helpful. Also made me realize that I've been doing model validation the long way around. – Dan Jun 27 '14 at 09:09

0 Answers0