简体   繁体   中英

HttpPostedFileBase status in asp.net mvc

An asp.net mvc action takes an HttpPostedFileBase parameter:

public ActionResult Save(HttpPostedFileBase file)
{
    //Q1: at the start of this action method, what's 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 begins to upload the file, the timer starts.when the user finished uploading the file(or my Save action is completed), the timer ends. How can I know when the user begins to upload?

First, have a look a this question for the basics : File Upload ASP.NET MVC 3.0

Q1 : The action is called once the file is fully available.

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, which 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) element within the Machine.config or Web.config file.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM