【发布时间】:2020-11-03 19:19:22
【问题描述】:
我有下面的控制器,玩家可以上传他们的宝藏图片。
有效!但是,当我使用 Postman 程序对其进行测试时,当我发出 Return OK() 时它不会返回任何内容。
如何让这个控制器向用户发送媒体已成功上传的消息?我以为返回 OK() 会这样做,但 Postman 中的响应字段是空白的。
有没有办法做到这一点?
谢谢!
[HttpPost]
public async Task<IActionResult> PostFormData([FromForm(Name = "file")] IFormFile userFileUpload, [FromForm] Guid treasureId)
{
int maxFileSize = 52428800;
var allowedExtensions = new[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".pdf", ".odt", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".rtf", ".txt" };
if(userFileUpload.Length > maxFileSize)
{
return BadRequest("Maximum file size exceeded");
}
if(!allowedExtensions.Contains(Path.GetExtension(userFileUpload.FileName)))
{
return BadRequest("This file is not a valid file type.");
}
if (treasureId == Guid.Empty)
{
return BadRequest("No treasureId was provided");
}
if (await _mediaFolderEngine.CopyFile(userFileUpload, treasureId))
{
return Ok();
}
else
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
【问题讨论】:
标签: asp.net-core entity-framework-core asp.net-core-webapi asp.net-core-3.1