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 wo... 玩家攻略推荐!poker world辅助,hhpkoer辅助挂是真的吗,我来教教你(有挂技巧);1分...
最新研发!哈糖大菠萝怎么开挂,... 最新研发!哈糖大菠萝怎么开挂,哈糖大菠萝挂,教你攻略(有挂辅助);致您一封信;亲爱哈糖大菠萝怎么开挂...
查到实测辅助!wepoker辅... 查到实测辅助!wepoker辅助器官方,wepoker线上大神,系统教程(有挂神器)这是由厦门游乐互...
总算清楚!pokermaste... 1、总算清楚!pokermaster修改器,hhpoker德州透视,力荐教程(有挂方法)。2、pok...
玩家必备攻略!wepoker有... 玩家必备攻略!wepoker有辅助插件吗,xpoker怎么作弊,透明教程(有挂攻略)是由北京得wep...
揭秘关于!wpk插件,we p... 揭秘关于!wpk插件,we poker插件,扑克教程(有挂透明)是一款可以让一直输的玩家,快速成为一...
必看攻略!大菠萝免费辅助器,a... 必看攻略!大菠萝免费辅助器,aapoker透视脚本下载,2025新版技巧(有挂软件);玩家必备必赢加...
科技揭秘!wepoker透视破... 1、科技揭秘!wepoker透视破解版,wepoker有没有挂,普及教程(有挂软件)。2、wepok...
实测必看!hhpoker底牌透... 实测必看!hhpoker底牌透视脚本,wepoker怎么开辅助,wpk教程(有挂透明);1.hhpo...