I want to use the HttpPostedFile Class to upload one or more large files to an ASP.NET MVC controller from a web page. Using this class, uploaded files larger than 256 KB are buffered to disk, rather than held in server memory.
My understanding is that it can be done like this:
if (context.Request.Files.Count > 0)
{
string tempFile = context.Request.PhysicalApplicationPath;
for(int i = 0; i < context.Request.Files.Count; i++)
{
HttpPostedFile uploadFile = context.Request.Files[i];
if (uploadFile.ContentLength > 0)
{
uploadFile.SaveAs(string.Format("{0}{1}{2}",
tempFile,"Upload\\", uploadFile.FileName));
}
}
}
Is there a way to set a callback, or using some other method, return status periodically to the web page via AJAX or JSON so that a progress bar and percent completed can be displayed? What would the code look like?