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, downloaded files larger than 256 KB are buffered to disk and not stored in server memory.
I understand that this can be done as follows:
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 use some other method, periodically return the status to the web page via AJAX or JSON so that the progress bar and completion percentage can be displayed? What does the code look like?