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

Conversation

@nnarhinen
Copy link
Contributor

commented Oct 22, 2014

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);
Automatic Content-Type for FormData uploads
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

This comment has been minimized.

Copy link
Contributor Author

commented Nov 4, 2014

@mzabriskie ping?

@mzabriskie

This comment has been minimized.

Copy link
Member

commented Nov 4, 2014

@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

Merge pull request #22 from nnarhinen/formdata-content-type
Fixing issue with Content-Type when uploading FormData

@mzabriskie mzabriskie merged commit d93df70 into axios:master Nov 4, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@mzabriskie

This comment has been minimized.

Copy link
Member

commented Dec 11, 2014

This is available with version 0.4.2

@nnarhinen nnarhinen referenced this pull request Jan 25, 2015

Closed

Support file uploads #2

@powmedia

This comment has been minimized.

Copy link

commented Jan 30, 2015

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

This comment has been minimized.

Copy link
Member

commented Apr 8, 2015

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

@ppozniak

This comment has been minimized.

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.