Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core 2 - Missing content-type boundary

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: enter image description here

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:

enter image description here

Thanks in advance.

like image 217
mororo Avatar asked Aug 21 '18 07:08

mororo


2 Answers

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.

like image 172
kemsky Avatar answered Nov 20 '22 13:11

kemsky


You can add content-type: as multipart/form-data; boundary=--14737809831466499882746641449.

I am testing API on postman and added content-type like above it worked for me.

like image 1
BC TUBE Avatar answered Nov 20 '22 15:11

BC TUBE