In my application we set content-type = application/json
in interceptor.
But to upload a file content-type should be multipart/form-data
,i.e it will take contant-type = multipart/form-data
when we try to upload form data.
my question is how can I remove the content type set in interceptor while doing a post request to upload a file.
thanks, Harshavardhan
HTTP Interceptors is a special type of angular service that we can implement. It's used to apply custom logic to the central point between the client-side and server-side outgoing/incoming HTTP request and response. Keep in mind that the interceptor wants only HTTP requests.
Whenever a request is made, the interceptors handle it in between. They can also identify the response by performing Rxjs operators. The interceptors do not initiate the handle method and handle the requests at their level. The interceptor is used to perform various functions and methods to perform specific tasks.
To Remove Existing header
if (!req.headers.has('Content-Type')) {
req = req.clone({ headers: req.headers.delete('Content-Type','application/json') });
Adding new Headers
req = req.clone({ headers: req.headers.set('Content-Type', 'multipart/form-data')})
To check the current value of the header.
req.headers.get('Accept')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With