Streaming large file uploads to ASP.NET MVC -
I'm working for an application, I need to allow the user to upload a very large file - that is Probably many gigabytes - Unfortunately, through our website, ASP.NET MVC appears to load the entire request to load into RAM - not exactly ideal for such an application. Specifically, trying to solve this problem via code:
if (request.Method == "POST") {request.ContentLength = clientRequest.InputStream.Length; Var rgbBody = new byte [32768]; (Var requestStream = request.GetRequestStream ()) using {int cbRead; While ((cbRead = clientRequest.InputStream.Read (rgbBody, 0, rgbBody.Length)) gt; {fileStream.Write (rgbBody, 0, cbRead); }}}
The buffer-to-request-in-RAM fails to circumvent the psyche. Is there an easy way to work around this behavior?
It has been found that my initial code was originally correct; Only needed to change
request.ContentLength = clientRequest.InputStream.Length;
request. Contact lang = clientRequest.ContentLength;
Pre-stream in full request to determine the length of the content; The latter only examines the content-length
header, for which only the header is sent in full. This allows IIS to start streaming requests almost immediately, which completely eliminates the original problem.
Comments
Post a Comment