Streaming large file uploads to ASP.NET MVC

后端 未结 2 423
时光取名叫无心
时光取名叫无心 2020-11-30 17:08

For an application I\'m working on, I need to allow the user to upload very large files--i.e., potentially many gigabytes--via our website. Unfortunately, ASP.NET MVC appea

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 17:56

    It turns out that my initial code was basically correct; the only change required was to change

    request.ContentLength = clientRequest.InputStream.Length;
    

    to

    request.ContentLength = clientRequest.ContentLength;
    

    The former streams in the entire request to determine the content length; the latter merely checks the Content-Length header, which only requires that the headers have been sent in full. This allows IIS to begin streaming the request almost immediately, which completely eliminates the original problem.

提交回复
热议问题