Reputation: 597
I have an Angular Single Page Application which calls a .NET Core API.
The default set up creates HttpHeaders to pass a jwt token to the API and sets the content-type to application/json; charset=utf-8
To extend this application, I've been following "Angular Image Upload Made Easy" (https://www.youtube.com/watch?v=YkvqLNcJz3Y), but with my default headers, the image in FormData in the API was always null.
So I changed the content-type to multipart/form-data, but got the same result.
After much experimentation, I discovered that not setting a content-type at all works. I can still pass my jwt to authenticate the user and the image now uploads without any problems.
So, is it safe to leave out content-type in request options, or would it be better to insert the "correct" type and what would that be?
(In the example in the video, request options are added to monitor progress of the upload, but no headers are included - reportProgress:true, observe:'events')
Upvotes: 0
Views: 801