aspcoreAPI中多参数的文件上传
创始人
2024-09-20 01:30:37
0
  1. 在控制器中添加HttpPost方法:

[HttpPost("upload")] public async Task UploadFiles(IList files, string param1, int param2) { // 在这里处理上传的文件和其他参数 }

  1. 使用MultipartFormDataContent来构建HttpClient:

using System.Net.Http; using System.Net.Http.Headers;

var client = new HttpClient(); var content = new MultipartFormDataContent();

// 添加文件 foreach(var file in files) { var fileContent = new StreamContent(file.OpenReadStream()); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = file.FileName }; content.Add(fileContent, "files", file.FileName); }

// 添加其他参数 content.Add(new StringContent(param1), "param1"); content.Add(new StringContent(param2.ToString()), "param2");

// 发送请求 var response = await client.PostAsync("https://example.com/api/upload", content);

注意事项:

  • 在MultipartFormDataContent中添加文件时,第一个参数为'files”,第二个参数为文件名;
  • 在MultipartFormDataContent中添加其他参数时,第一个参数为参数名称,第二个参数为参数值。

相关内容

热门资讯

透视科技!红龙poker辅助工... 透视科技!红龙poker辅助工具(透视)竟然真的有挂(详细辅助可靠教程)1、红龙poker辅助透视辅...
透视ai代打!aapoker辅... 透视ai代打!aapoker辅助插件工具(透视)原来真的是有挂(详细辅助必备教程)1)aapoker...
透视模拟器!wepoker有人... 透视模拟器!wepoker有人用过吗(透视)真是有挂(详细辅助2025新版教程)1、每一步都需要思考...
透视计算!pokermaste... 透视计算!pokermaster破解版(透视)一直是有挂(详细辅助必胜教程)1、玩家可以在软件透明挂...
透视教程!wepoker破解器... 透视教程!wepoker破解器激活码(透视)一直真的是有挂(详细辅助攻略教程)1)辅助挂:进一步探索...
透视ai代打!wepoker买... 透视ai代打!wepoker买钻石有用吗(透视)切实是有挂(详细辅助2025新版)1、起透看视 透明...
透视代打!wepoker透视脚... 透视代打!wepoker透视脚本免费下载(透视)果然是真的有挂(详细辅助必胜教程);1、wepoke...
透视攻略!hhpoker的辅助... 透视攻略!hhpoker的辅助是真的吗(透视)其实是有挂(详细辅助新版2025教程)1、完成透视辅助...
透视攻略!wepoker透视脚... 透视攻略!wepoker透视脚本免费下载pc(透视)竟然存在有挂(详细辅助教你攻略);1)wepok...
透视插件!聚星ai辅助工具下载... 透视插件!聚星ai辅助工具下载(透视)原来真的有挂(详细辅助揭秘教程);辅助器中分为三种模型:软件透...