我知道已经有一个类似的问题,但它没有解决上述错误。
这是我在 API 控制器中的 PUT 操作,并且运行良好Swagger:
[HttpPut("{id}/upload")]
public async Task<IActionResult> UploadFile(string id, IFormFile file)
{
// codes using id above are omitted, nothing to do with the error
var path = Path.Combine(
Directory.GetCurrentDirectory(),
"wwwroot",
file.FileName
);
using (var stream = new FileStream(path, FileMode.Create))
{
await file.CopyToAsync(stream);
}
return Ok();
}
Run Code Online (Sandbox Code Playgroud)
以下是我的 Angular 网页中的代码:
超文本标记语言
<input type="file" (change)="setFile($event.target.files)"/>
<button (click)="save()"> Save </button>
Run Code Online (Sandbox Code Playgroud)
打字稿
forUpload: File = null;
@Input() someModel: SomeModel;
// setting of file
setFile(myFile: File){
if …Run Code Online (Sandbox Code Playgroud)