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

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

        <legend id='vDOe0'><style id='vDOe0'><dir id='vDOe0'><q id='vDOe0'></q></dir></style></legend>
          <bdo id='vDOe0'></bdo><ul id='vDOe0'></ul>
      1. <tfoot id='vDOe0'></tfoot>
      2. ASP.NET CORE 中的 Request.Files

        时间:2023-06-02

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

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

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

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试使用 ajax 请求使用 aspnet 核心上传文件.在以前版本的 .net 中,我曾经使用

                  I am trying to upload files using aspnet core using ajax request . In previous versions of .net i used to handle this using

                   foreach (string fileName in Request.Files)
                              {
                                  HttpPostedFileBase file = Request.Files[fileName];
                                  //Save file content goes here
                  
                                  fName = file.FileName;
                       (...)
                  

                  但现在它在 request.files 处显示错误我怎样才能让它工作?搜了一下发现httppostedfile已经改成了iformfile但是request.files怎么处理呢?

                  but now its showing error at request.files how can i get it to work ? i searched and found that httppostedfile has been changed to iformfile but how to handle request.files?

                  推荐答案

                  这是来自最近项目的工作代码.数据已从 Request.Files 移至 Request.Form.Files.如果您需要将流转换为字节数组 - 这是唯一对我有用的实现.其他人会返回空数组.

                  This is working code from a recent project. Data has been moved from Request.Files to Request.Form.Files. In case you need to convert stream to byte array - this is the only implementation that worked for me. Others would return empty array.

                  using System.IO;
                  var filePath = Path.GetTempFileName();
                  foreach (var formFile in Request.Form.Files)
                  {
                     if (formFile.Length > 0)
                     {
                        using (var inputStream = new FileStream(filePath, FileMode.Create))
                        {
                           // read file to stream
                           await formFile.CopyToAsync(inputStream);
                           // stream to byte array
                           byte[] array = new byte[inputStream.Length];
                           inputStream.Seek(0, SeekOrigin.Begin);
                           inputStream.Read(array, 0, array.Length);
                           // get file name
                           string fName = formFile.FileName;
                        }
                     }
                  }
                  

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

                  上一篇:上传超过 Asp.net 请求长度限制的文件? 下一篇:如何通过 ASP.NET MVC 上传文件并显示进度条?

                  相关文章

                  最新文章

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

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

                      <bdo id='r1uzf'></bdo><ul id='r1uzf'></ul>
                    <legend id='r1uzf'><style id='r1uzf'><dir id='r1uzf'><q id='r1uzf'></q></dir></style></legend>

                    1. <tfoot id='r1uzf'></tfoot>