using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.IO; using System.IO.Compression; namespace WebApplication1.Controllers { [Route("api/[controller]/[action]")] [ApiController] public class ValuesController1 : ControllerBase { private readonly string BaseUpload = "D:\\uploads";//上传地址 /// <summary> /// 多文件上传 /// </summary> /// <param name="files"></param> /// <returns></returns> [HttpPost] public async Task<IActionResult> Upload(List<IFormFile> files) { // 遍历上传的文件列表 foreach (var file in files) { // 保存文件到固定目录 var filePath = Path.Combine(BaseUpload, file.FileName); using (var stream = System.IO.File.Create(filePath)) { await file.CopyToAsync(stream); } } return Ok("上传成功"); } } }
注意: 需要先在d盘创建 uploads文件夹
标签:webapi,IO,前端,System,file,var,using,上传 From: https://www.cnblogs.com/tlfe/p/18231749