<bdo id='bvorQ'></bdo><ul id='bvorQ'></ul>

<small id='bvorQ'></small><noframes id='bvorQ'>

  • <tfoot id='bvorQ'></tfoot>

    <i id='bvorQ'><tr id='bvorQ'><dt id='bvorQ'><q id='bvorQ'><span id='bvorQ'><b id='bvorQ'><form id='bvorQ'><ins id='bvorQ'></ins><ul id='bvorQ'></ul><sub id='bvorQ'></sub></form><legend id='bvorQ'></legend><bdo id='bvorQ'><pre id='bvorQ'><center id='bvorQ'></center></pre></bdo></b><th id='bvorQ'></th></span></q></dt></tr></i><div id='bvorQ'><tfoot id='bvorQ'></tfoot><dl id='bvorQ'><fieldset id='bvorQ'></fieldset></dl></div>

  • <legend id='bvorQ'><style id='bvorQ'><dir id='bvorQ'><q id='bvorQ'></q></dir></style></legend>

      1. 将大文件上传到 ASP.NET MVC

        时间:2023-06-02
        • <i id='ekEKL'><tr id='ekEKL'><dt id='ekEKL'><q id='ekEKL'><span id='ekEKL'><b id='ekEKL'><form id='ekEKL'><ins id='ekEKL'></ins><ul id='ekEKL'></ul><sub id='ekEKL'></sub></form><legend id='ekEKL'></legend><bdo id='ekEKL'><pre id='ekEKL'><center id='ekEKL'></center></pre></bdo></b><th id='ekEKL'></th></span></q></dt></tr></i><div id='ekEKL'><tfoot id='ekEKL'></tfoot><dl id='ekEKL'><fieldset id='ekEKL'></fieldset></dl></div>
          <tfoot id='ekEKL'></tfoot>

                <tbody id='ekEKL'></tbody>
                <bdo id='ekEKL'></bdo><ul id='ekEKL'></ul>

                <small id='ekEKL'></small><noframes id='ekEKL'>

                1. <legend id='ekEKL'><style id='ekEKL'><dir id='ekEKL'><q id='ekEKL'></q></dir></style></legend>
                  本文介绍了将大文件上传到 ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  对于我正在开发的应用程序,我需要允许用户通过我们的网站上传非常大的文件(即可能有很多千兆字节).不幸的是,ASP.NET MVC 似乎在开始为它提供服务之前将整个请求加载到 RAM 中——对于这样的应用程序来说并不完全理想.值得注意的是,试图通过如下代码来规避这个问题:

                  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 appears to load the entire request into RAM before beginning to service it--not exactly ideal for such an application. Notably, trying to circumvent the issue via code such as the following:

                  if (request.Method == "POST")
                  {
                      request.ContentLength = clientRequest.InputStream.Length;
                      var rgbBody = new byte[32768];
                  
                      using (var requestStream = request.GetRequestStream())
                      {
                          int cbRead;
                          while ((cbRead = clientRequest.InputStream.Read(rgbBody, 0, rgbBody.Length)) > 0)
                          {
                              fileStream.Write(rgbBody, 0, cbRead);
                          }
                      }
                  }
                  

                  未能规避将请求缓冲到 RAM 的心态.有没有一种简单的方法可以解决此问题?

                  fails to circumvent the buffer-the-request-into-RAM mentality. Is there an easy way to work around this behavior?

                  推荐答案

                  原来我的初始代码基本正确;唯一需要改变的就是改变

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

                  request.ContentLength = clientRequest.InputStream.Length;
                  

                  request.ContentLength = clientRequest.ContentLength;
                  

                  前者在整个请求流中确定内容长度;后者仅检查 Content-Length 标头,它只要求标头已完整发送.这允许 IIS 几乎立即开始流式传输请求,从而完全消除了最初的问题.

                  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.

                  这篇关于将大文件上传到 ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:C# HttpClient 4.5 多部分/表单数据上传 下一篇:将文件上传到数据库的最佳实践

                  相关文章

                  最新文章

                2. <small id='JkCjo'></small><noframes id='JkCjo'>

                  <i id='JkCjo'><tr id='JkCjo'><dt id='JkCjo'><q id='JkCjo'><span id='JkCjo'><b id='JkCjo'><form id='JkCjo'><ins id='JkCjo'></ins><ul id='JkCjo'></ul><sub id='JkCjo'></sub></form><legend id='JkCjo'></legend><bdo id='JkCjo'><pre id='JkCjo'><center id='JkCjo'></center></pre></bdo></b><th id='JkCjo'></th></span></q></dt></tr></i><div id='JkCjo'><tfoot id='JkCjo'></tfoot><dl id='JkCjo'><fieldset id='JkCjo'></fieldset></dl></div>
                  <tfoot id='JkCjo'></tfoot>
                      <bdo id='JkCjo'></bdo><ul id='JkCjo'></ul>
                    1. <legend id='JkCjo'><style id='JkCjo'><dir id='JkCjo'><q id='JkCjo'></q></dir></style></legend>