-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP Module using wrong Content-Type for multipart/form-data #37597
Comments
I think, I also hit this bug. In my case, my const formData = new FormData();
formData.append('image', image);
let headers = new HttpHeaders();
headers = headers.append('Content-Type', 'multipart/form-data');
headers = headers.append('enctype', 'multipart/form-data');
this.http
.post(url, formData, {headers}).subscribe(_ => {}); Whatever I have tried, like not setting any header, in network tab of dev tools shows me the _ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 10.0.7
Node: 14.8.0
OS: linux x64
Angular: 10.0.11
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.1000.7
@angular-devkit/build-angular 0.1000.7
@angular-devkit/build-optimizer 0.1000.7
@angular-devkit/build-webpack 0.1000.7
@angular-devkit/core 10.0.7
@angular-devkit/schematics 10.0.7
@angular/cdk 10.1.3
@angular/cli 10.0.7
@angular/material 10.1.3
@ngtools/webpack 10.0.7
@schematics/angular 10.0.7
@schematics/update 0.1000.7
rxjs 6.6.2
typescript 3.9.7
webpack 4.43.0 |
@bwqr Did you mean to do this.http
.post(url, formData, { headers }).subscribe(_ => {}); |
@JoostK exactly, my miss |
I am indeedly sorry for misinformation. The cause of my problem is the http interceptor, which is setup by myself. I was overriding the content-type in interceptor. After fixing the interceptor, my request's headers are sent as expected. |
I think, this bug report has nothing to do with angular/common/http. While sending a formData, explicitly setting
with correct values. |
Duplicate of #36274. |
My mistake, re-opening. This is in reference to the request headers, not the response as #36274. |
|
any update on this issue...! |
Yes, the original issue was resolved for me since at least version 12. Possibly sooner. Just update and try as per the desired method using the HTTP method in my original post and all should be well. |
@endigo9740 , this is something I am trying but still the same issue in angular - 12.1.4
any sugegstions...! |
There is no need to pass header in post request, browser automatically passed content type as multipart/form-data if you're passing FormData object:
In my case i written |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 bug report
Affected Package
The issue is is affecting package @angular/common/http
Is this a regression?
Not sure, only tested on Angular version 9.1.7
Description
Currently trying to upload a large file from Angular v9.1.7 to a Django API. I've been receiving the following error:
Multipart form parse error - Invalid boundary in multipart: None
Chrome's dev tools request header shows:
Content-Type: multipart/form-data
But should resemble the following:
Content-Type: multipart/form-data;boundary=----WebKitFormBoundaryyrV7KO0BoCBuDbTL
See the full discussion for this issue here:
JakeChampion/fetch#505
(@dgraham's response)
🔬 Minimal Reproduction
Here's a minimal sample of what's being used in Angular:
Here's my work around using the Github link provided in the description above:
Note that Fetch does not append a default content-type like the HTTP module. This means there is no satisfactory work around without using Fetch in place of the HTTP module currently.
🔥 Exception or Error
Multipart form parse error - Invalid boundary in multipart: None
Chrome's dev tools request header shows:
Content-Type: multipart/form-data
But should resemble the following:
Content-Type: multipart/form-data;boundary=----WebKitFormBoundaryyrV7KO0BoCBuDbTL
🌍 Your Environment
Angular Version:
Tested in Chrome version 83.0.4103.97
The text was updated successfully, but these errors were encountered: