mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
Fixed isFormData predicate; (#4413)
Added support for automatic object serialization to FormData if `Content-Type` is `multipart/form-data`; Added support for FormData to be overloaded using `config.env.FormData` option; Added support for FormData in node.js environment through `form-data` package;
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('../utils');
|
||||
|
||||
function combinedKey(parentKey, elKey) {
|
||||
return parentKey + '.' + elKey;
|
||||
}
|
||||
@@ -11,7 +13,7 @@ function buildFormData(formData, data, parentKey) {
|
||||
});
|
||||
} else if (
|
||||
typeof data === 'object' &&
|
||||
!(data instanceof File || data === null)
|
||||
!(utils.isFile(data) || data === null)
|
||||
) {
|
||||
Object.keys(data).forEach(function buildObject(key) {
|
||||
buildFormData(
|
||||
@@ -44,10 +46,12 @@ function buildFormData(formData, data, parentKey) {
|
||||
* type FormVal = FormDataNest | FormDataPrimitive
|
||||
*
|
||||
* @param {FormVal} data
|
||||
* @param {?Object} formData
|
||||
*/
|
||||
|
||||
module.exports = function getFormData(data) {
|
||||
var formData = new FormData();
|
||||
module.exports = function getFormData(data, formData) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
formData = formData || new FormData();
|
||||
|
||||
buildFormData(formData, data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user