【发布时间】:2021-03-03 19:39:21
【问题描述】:
我有一个包含一些图像的实体,我想使用 HttpPatch 方法对其进行更新。
要创建新样式,我使用以下方法:
[HttpPost]
public async Task<IActionResult> CreateStyleAsync([FromForm] StyleFiles styleFiles, [FromForm] StyleDTO style)
现在我正在尝试创建一个方法来使用 HttpPatch 方法更新此样式。我试过了,但没有选项可以在 Swagger 上上传文件:
[HttpPatch("{styleId}")]
public async Task<IActionResult> PatchStyleAsync([FromForm] StyleFiles styleFiles, Guid styleId, [FromBody] JsonPatchDocument styleDto)
这是我在 Swagger 上看到的: Patch method on Swagger
这是 DTO:
public class StyleDTO
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string PreviewImage { get; set; }
}
这是 StyleFiles 类:
public class StyleFiles
{
public IFormFile Image { get; set; }
}
我正在考虑创建两个单独的端点,一个用于更新文件,另一个用于更新实体本身。但我不想那样做。
【问题讨论】:
-
我不希望 swaggerui 为上传文件渲染任何内容,无论使用 http 方法。您是否考虑过使用更高级的休息工具,例如postman?
标签: c# asp.net-core .net-core swagger http-patch