2
0
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:
Dmitriy Mozgovoy
2022-02-02 13:48:44 +02:00
committed by GitHub
parent cc86c6c49f
commit 73e3bdb883
6 changed files with 40 additions and 15 deletions
+7 -3
View File
@@ -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);