mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +03:00
feat(fomdata): added support for spec-compliant FormData & Blob types; (#5316)
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
|
||||
import utils from '../utils.js';
|
||||
import AxiosError from '../core/AxiosError.js';
|
||||
import envFormData from '../env/classes/FormData.js';
|
||||
// temporary hotfix to avoid circular references until AxiosURLSearchParams is refactored
|
||||
import PlatformFormData from '../platform/node/classes/FormData.js';
|
||||
|
||||
/**
|
||||
* Determines if the given thing is a array or js object.
|
||||
@@ -59,17 +60,6 @@ const predicates = utils.toFlatObject(utils, {}, null, function filter(prop) {
|
||||
return /^is[A-Z]/.test(prop);
|
||||
});
|
||||
|
||||
/**
|
||||
* If the thing is a FormData object, return true, otherwise return false.
|
||||
*
|
||||
* @param {unknown} thing - The thing to check.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isSpecCompliant(thing) {
|
||||
return thing && utils.isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a data object to FormData
|
||||
*
|
||||
@@ -99,7 +89,7 @@ function toFormData(obj, formData, options) {
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
formData = formData || new (envFormData || FormData)();
|
||||
formData = formData || new (PlatformFormData || FormData)();
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
options = utils.toFlatObject(options, {
|
||||
@@ -117,7 +107,7 @@ function toFormData(obj, formData, options) {
|
||||
const dots = options.dots;
|
||||
const indexes = options.indexes;
|
||||
const _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
|
||||
const useBlob = _Blob && isSpecCompliant(formData);
|
||||
const useBlob = _Blob && utils.isSpecCompliantForm(formData);
|
||||
|
||||
if (!utils.isFunction(visitor)) {
|
||||
throw new TypeError('visitor must be a function');
|
||||
|
||||
Reference in New Issue
Block a user