2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-08 17:22:34 +03:00

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);

```
This commit is contained in:
Niklas Närhinen
2014-10-23 01:49:25 +03:00
parent 789baf3a58
commit 2f4d0b8b45
2 changed files with 15 additions and 0 deletions
+4
View File
@@ -21,6 +21,10 @@ module.exports = function xhrAdapter(resolve, reject, config) {
config.headers || {}
);
if (utils.isFormData(data)) {
delete headers['Content-Type']; // Let the browser set it
}
// Create the request
var request = new(XMLHttpRequest || ActiveXObject)('Microsoft.XMLHTTP');
request.open(config.method, buildUrl(config.url, config.params), true);