Skip to content
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

Automatic Content-Type for FormData uploads #22

Merged
merged 1 commit into from Nov 4, 2014
Merged

Automatic Content-Type for FormData uploads #22

merged 1 commit into from Nov 4, 2014

Conversation

nnarhinen
Copy link
Contributor

When data passed to axios is of type FormData we have to let the browser
create the Content-Type header so that the boundaries will get right
etc.

Usage:

var data = new FormData();
data.append('field', 'some string');
data.append('file', someFile);

var opts = {
  transformRequest: function(data) { return data; }
};

axios.post('/fileupload', data, opts);

When data passed to axios is of type FormData we have to let the browser
create the Content-Type header so that the boundaries will get right
etc.

Usage:

```js
var data = new FormData();
data.append('field', 'some string');
data.append('file', someFile);

var opts = {
  transformRequest: function(data) { return data; }
};

axios.post('/fileupload', data, opts);

```
@nnarhinen
Copy link
Contributor Author

@mzabriskie ping?

@mzabriskie
Copy link
Member

@nnarhinen sorry for the delay, I have been overloaded lately. Your PR looks good.

mzabriskie added a commit that referenced this pull request Nov 4, 2014
Fixing issue with Content-Type when uploading FormData
@mzabriskie mzabriskie merged commit d93df70 into axios:master Nov 4, 2014
@mzabriskie
Copy link
Member

This is available with version 0.4.2

@nnarhinen nnarhinen mentioned this pull request Jan 25, 2015
@powmedia
Copy link

This is working for me however the fact you need to implement a pass-through transformRequest() seems like an unnecessary step. If the library is detecting FormData anyway could it skip the need for this requirement?

@mzabriskie
Copy link
Member

@powmedia there was a bug #53 that was causing this to be necessary. It is no longer needed.

@ppozniak
Copy link

ppozniak commented Apr 3, 2019

Necro-posting, but still wonder why that happened, as per the spec it is possible to set up custom boundary for formdata.
Content-Type: multipart/form-data; boundary=something
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type#Syntax

@axios axios locked and limited conversation to collaborators May 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants