ASP.NET Core 2-缺少内容类型边界 [英] ASP.NET Core 2 - Missing content-type boundary

查看:70
本文介绍了ASP.NET Core 2-缺少内容类型边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件从Angular客户端上传到我的ASP.NET Core 2 WebAPI服务.当我调用该服务时,我返回一个内部服务器错误.那就是我得到的错误:

我在客户端使用的组件就是这个组件:

谢谢.

解决方案

在开发人员工具的网络"标签中检查上传请求,它的格式应正确(匹配'Content-Type':'multipart/form-data'),也可以尝试删除此标头.

I'm trying to upload a file from a Angular client to my ASP.NET Core 2 WebAPI service. When I call the service, I get back an Internal Server Error. That's the error I'm getting:

The component I'm using client-side is this one: ngx-uploader

In my request options, i set them as you can see here:

  const event: UploadInput = {
  type: 'uploadAll',
  url: this.printService.apiFilesBaseUrl + '/Upload',
  method: 'POST',
  file: this.files[0],
  headers: {
    'Content-Type': 'multipart/form-data',
    'Accept': '*/*',
    'Authorization': 'Bearer ' + this.authService.getToken()
  }
};

While, server-side my controller action signature is this one:

    [HttpPost]
    [Route("Upload")]
    [Authorize]
    public Guid Post(IFormFile file)

Breakpoints in this controller action never get hit.

Can someone please share ideas about what's happening here?

Here, as requested, i will post my request header and payload:

Thanks in advance.

解决方案

Check upload request in developer tools network tab, it should have correct format (matching 'Content-Type': 'multipart/form-data'), also you could try removing this header.

这篇关于ASP.NET Core 2-缺少内容类型边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆