【发布时间】:2021-05-26 18:57:36
【问题描述】:
我编写代码以通过文件上传从表单发布数据
[HttpPost]
public ActionResult<Models.Event> CreateEvent(Models.Event events, IFormFile file)
{
string dbPath = null;
var folderName = Path.Combine("wwwroot");
var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName);
if (file.Length > 0)
{
using var image = Image.Load(file.OpenReadStream());
image.Mutate(x => x.Resize(112, 112));
var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
var fullPath = Path.Combine(pathToSave, fileName);
dbPath = Path.Combine("api/event/items/pic/", fileName);
image.Save(fullPath);
}
events.LogoImageFilePath = dbPath;
_eventService.CreateEvent(events);
return Ok(events);
}
这是我的模型事件
public class Event
{
public string Id { get; set; }
public string Name { get; set; }
public string LogoImageFilePath { get; set; }
}
当我使用 Postman 发布数据时
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.13",
"title": "Unsupported Media Type",
"status": 415,
"traceId": "00-e6310fde4fabb24ca3fd39a897475187-f3154d2024ff8f4f-00"
}
我该如何解决这个问题?谢谢你。 这是我的邮递员请求 标题选项卡
【问题讨论】:
-
您发送的“Content-Type”标头的值是多少?
-
您还应该分享您的 Postman 请求。否则,谁能帮助你?
-
我更新了我的 Postman 请求的图片。
-
我认为你需要用
[FromBody]装饰events控制器参数