Asp.net core .net core 2.2 webapi和处理多部分请求
我有.NETCore2.2WebAPI作为后端。 我的后端必须处理来自移动应用程序的请求(照片和文本),作为多部分形式的请求。Asp.net core .net core 2.2 webapi和处理多部分请求,asp.net-core,asp.net-core-webapi,Asp.net Core,Asp.net Core Webapi,我有.NETCore2.2WebAPI作为后端。 我的后端必须处理来自移动应用程序的请求(照片和文本),作为多部分形式的请求。 请提示我如何在后端进行prpvide?此问题已解决 public class SwaggerFileOperationFilter : IOperationFilter { public void Apply(Operation operation, OperationFilterContext context) { if (op
请提示我如何在后端进行prpvide?此问题已解决
public class SwaggerFileOperationFilter : IOperationFilter
{
public void Apply(Operation operation, OperationFilterContext context)
{
if (operation.OperationId == "MailWithPhotos")
{
operation.Parameters = new List<IParameter>
{
new NonBodyParameter
{
Name = "awr_file",
Required = false,
Type = "file",
In = "formData"
},
new NonBodyParameter
{
Name = "awr_message",
Required = true,
Type = "string",
In = "formData"
},
new NonBodyParameter
{
Type = "string",
In = "header",
Name = "Authorization",
Description = "token",
Required = true
}
};
}
}
}
[HttpPost]
[ProducesResponseType(typeof(ResponseMail), 200)]
public async Task<PipeResponse> MailWithPhotos([FromForm] MailwithPhoto fIleUploadAPI)
{
var file = fIleUploadAPI.awr_file; // OK!!!
var message = fIleUploadAPI.awr_message; // OK!!!
var tokenA = Request.Headers["Authorization"]; // OK!!!
var fileContentStream11 = new MemoryStream();
await fIleUploadAPI.awr_file.CopyToAsync(fileContentStream11);
await System.IO.File.WriteAllBytesAsync(Path.Combine(folderPath,
fIleUploadAPI.awr_file.FileName),
fileContentStream11.ToArray());
有很多例子。在谷歌搜索“NETCore2.2WebAPI多部分/表单数据”时,产生了一系列循序渐进的教程(如我将从这里开始的教程)。
public class MailwithPhoto
{
public string awr_message { get; set; }
public string Authorization { get; set; }
public IFormFile awr_file { get; set; }
}