HttpPostedFileBase status in asp.net mvc

The asp.net mvc action takes a HttpPostedFileBase parameter:

public ActionResult Save(HttpPostedFileBase file)
{
    //Q1: at the start of this action method, what the status of this file? 
    //UploadCompleted or Uploading or something else?

    //Q2: where is the file stored? memory or a temp file?

    if (answer of Q1 is Uploading)
    {
        //Q3a: what happens if file.SaveAs is invoked? 
        //block the current thread until the file is uploaded?
    }
    else if (answer if Q1 is UploadCompleted)
    {
        //Q3b: which means the developer can do nothing before the file is uploaded?
        //if the business logic limits the size of the file(e.g. <= 5MB), how can we
        //prevent evil-intended uploading?
    }
}

      

Q4 here: I want to record the total time of this request, when the user starts uploading the file, the timer starts. When the user has finished downloading the file (or my action is Save

complete), the timer ends. How do I know when a user starts downloading?

+3


source to share


1 answer


First, take a look at this question for the basics: ASP.NET MVC 3.0 File Uploads

Q1: The action is called when the file is fully accessible.

Q2: From msdn: http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.aspx



The amount of data that is buffered in server memory for a request that includes file uploads can be specified by accessing the RequestLengthDiskThreshold property or by setting the requestLengthDiskThreshold attribute of the httpRuntime element (ASP.NET Settings Schema) in the Machine.config file or Web.config file ...

Q3: you can specify the max upload size in web.config: How to increase max upload size in ASP.NET?

+1


source







All Articles