小编Lin*_*ngh的帖子

上传文件时出现错误 415 不支持的媒体类型

我知道已经有一个类似的问题,但它没有解决上述错误。

这是我在 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)

c# rxjs typescript asp.net-core angular

2
推荐指数
1
解决办法
3926
查看次数

标签 统计

angular ×1

asp.net-core ×1

c# ×1

rxjs ×1

typescript ×1