1. <i id='3Z9MK'><tr id='3Z9MK'><dt id='3Z9MK'><q id='3Z9MK'><span id='3Z9MK'><b id='3Z9MK'><form id='3Z9MK'><ins id='3Z9MK'></ins><ul id='3Z9MK'></ul><sub id='3Z9MK'></sub></form><legend id='3Z9MK'></legend><bdo id='3Z9MK'><pre id='3Z9MK'><center id='3Z9MK'></center></pre></bdo></b><th id='3Z9MK'></th></span></q></dt></tr></i><div id='3Z9MK'><tfoot id='3Z9MK'></tfoot><dl id='3Z9MK'><fieldset id='3Z9MK'></fieldset></dl></div>
  2. <small id='3Z9MK'></small><noframes id='3Z9MK'>

    <legend id='3Z9MK'><style id='3Z9MK'><dir id='3Z9MK'><q id='3Z9MK'></q></dir></style></legend>
      • <bdo id='3Z9MK'></bdo><ul id='3Z9MK'></ul>

      <tfoot id='3Z9MK'></tfoot>

      Asp.Net Core 2.0 中的“HttpPostedFileBase"

      时间:2023-07-11

          <legend id='gGQf0'><style id='gGQf0'><dir id='gGQf0'><q id='gGQf0'></q></dir></style></legend>
          • <tfoot id='gGQf0'></tfoot>

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

              • <bdo id='gGQf0'></bdo><ul id='gGQf0'></ul>

                  <tbody id='gGQf0'></tbody>
              • <i id='gGQf0'><tr id='gGQf0'><dt id='gGQf0'><q id='gGQf0'><span id='gGQf0'><b id='gGQf0'><form id='gGQf0'><ins id='gGQf0'></ins><ul id='gGQf0'></ul><sub id='gGQf0'></sub></form><legend id='gGQf0'></legend><bdo id='gGQf0'><pre id='gGQf0'><center id='gGQf0'></center></pre></bdo></b><th id='gGQf0'></th></span></q></dt></tr></i><div id='gGQf0'><tfoot id='gGQf0'></tfoot><dl id='gGQf0'><fieldset id='gGQf0'></fieldset></dl></div>
              • 本文介绍了Asp.Net Core 2.0 中的“HttpPostedFileBase"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我最近正在开发一个调用 API(使用 .NET Core 2.0 开发)的 ReactJS 应用程序.

                I'm recently working on a ReactJS app that's calling an API (developed with .NET Core 2.0).

                我的问题是如何在 .NET Core 2.0 API 中使用 HttpPostedFileBase 来获取文件内容并将其保存在数据库中.

                My question is how to use HttpPostedFileBase in an .NET Core 2.0 API in order to get file content and save it in database.

                推荐答案

                你在 ASP.NET Core 2.0 中没有 HttpPostedFileBase,但是你可以使用 IFormFile.

                You don't have HttpPostedFileBase in ASP.NET Core 2.0, but you can use IFormFile.

                [HttpPost("UploadFiles")]
                public async Task<IActionResult> Post(List<IFormFile> files)
                {
                    long size = files.Sum(f => f.Length);
                
                    // full path to file in temp location
                    var filePath = Path.GetTempFileName();
                
                    foreach (var formFile in files)
                    {
                        if (formFile.Length > 0)
                        {
                            using (var stream = new FileStream(filePath, FileMode.Create))
                            {
                                await formFile.CopyToAsync(stream);
                            }
                        }
                    }
                
                    // process uploaded files
                    // Don't rely on or trust the FileName property without validation.
                
                    return Ok(new { count = files.Count, size, filePath});
                }
                

                更多:https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-2.1

                IFormFile 位于以下命名空间 Microsoft.AspNetCore.Http.

                IFormFile is in the following namespace Microsoft.AspNetCore.Http.

                这篇关于Asp.Net Core 2.0 中的“HttpPostedFileBase"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何自定义 text-danger 给出的验证错误消息? 下一篇:ASP.NET 5:响应中的访问控制允许来源

                相关文章

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

              • <tfoot id='pKg8R'></tfoot>
                • <bdo id='pKg8R'></bdo><ul id='pKg8R'></ul>
                <legend id='pKg8R'><style id='pKg8R'><dir id='pKg8R'><q id='pKg8R'></q></dir></style></legend>

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