我想在ASP.NET Core 6中创建一个简单的文件上传端点,并认为它应该像这篇文章描述的那样容易:https://dotnetthoughts.net/handling-file-uploads-in-openapi-with-aspnet-core/。
当我定义了一个端点,例如:
app.MapPost("/upload", (IFormFile file) =>
{
//Do something with the file
return Results.Ok();
}).Accepts<IFormFile>("multipart/form-data").Produces(200);
当我调用端点时,返回了415错误。我收到的消息大致是:期望支持JSON格式的媒体类型,但实际接收到的是"multipart/form-data; ..."。不确定为什么会期望支持JSON格式,当我说该端点应该接受“multipart/form-data”。这里有什么想法或建议吗?
Accepts<IFormFile>("multipart/form-data")
,我猜这就是为什么asp.net尝试读取body的原因。但是我似乎没有非泛型的Accepts
可以使用。 - Tomas Jansson