IIS asp.net mvc partially? File downloaded

Given the following code, which is extremely general, I was hoping someone could tell me a little bit about what goes on behind the scenes ...

[HttpPost] public ActionResult Load(Guid regionID, HttpPostedFileBase file) { if (file.ContentLength == 0) RedirectToAction("blablabla....."); var fileBytes = new byte[file.ContentLength]; file.InputStream.Read(fileBytes, 0, file.ContentLength); } 

In particular, is the file fully uploaded to the server before the action method is called? Or is it a call to the file.InputStream.Read () method that calls or rather waits for the entire file to load. Can I do partial reads in a stream and access the β€œchunks” of a file as it is loading? (If all the fire is loaded before my method starts, then everything will be debatable.)

Can someone please give me some good info on internal work here. Is there any difference between IIS6 or II7 here?

Thanks,

+3
source share
1 answer

The while file must be sent to the server before the action method is called. Quote from the documentation :

Files are downloaded in the MIME format multipart / form-data. From the default, all requests, including the form of fields and downloaded files, are larger than 256 KB buffered to disk rather than to server memory.

You can specify the maximum allowable request size by accessing the MaxRequestLength property or setting the maxRequestLength attribute of the httpRuntime element (ASP.NET Schema Element) in Machine.config or in the Web.config file. the default is 4 MB.

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

Server memory will not be consumed on the server, but the contents of the file will be buffered to disk. After the client has sent the whole file, the ASP.NET pipeline will trigger the action of your controller, and you can read the request stream in pieces and save it in another file, which will be the final location of the downloaded file. The action cannot be called before the file completes the download, since the multipart/form-data file that appears after the file may contain other fields, in which case they will not be assigned.

+5
source

Source: https://habr.com/ru/post/1333367/


All Articles