diff --git a/package.json b/package.json index 2ac437c..1e61b59 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bytedo/fetch", - "version": "2.1.1", + "version": "2.1.2", "description": "全新的ajax封装。分2个版本, 一个基于XMLHttpRequest, 一个基于window.fetch", "main": "dist/index.js", "files": [ diff --git a/src/index.js b/src/index.js index 726f769..b5456b2 100644 --- a/src/index.js +++ b/src/index.js @@ -127,7 +127,10 @@ class _Request { params = options.body } else { for (let k in options.body) { - if (toS.call(options.body[k]) === '[object File]') { + if ( + toS.call(options.body[k]) === '[object File]' || + toS.call(options.body[k]) === '[object Blob]' + ) { hasAttach = true break } diff --git a/src/lib/format.js b/src/lib/format.js index c99cc48..a17536c 100644 --- a/src/lib/format.js +++ b/src/lib/format.js @@ -15,7 +15,7 @@ export const decode = decodeURIComponent function serialize(p, obj, query) { var k if (Array.isArray(obj)) { - obj.forEach(function(it, i) { + obj.forEach(function (it, i) { k = p ? `${p}[${Array.isArray(it) ? i : ''}]` : i if (typeof it === 'object') { serialize(k, it, query) @@ -84,7 +84,7 @@ export const Format = { for (let i in data) { let el = data[i] if (Array.isArray(el)) { - el.forEach(function(it) { + el.forEach(function (it) { form.append(i + '[]', it) }) } else { @@ -99,13 +99,13 @@ export const Format = { } let arr = [] - let query = function(k, v) { + let query = function (k, v) { if (/native code/.test(v)) { return } v = typeof v === 'function' ? v() : v - v = toS.call(v) === '[object File]' ? v : encode(v) + v = toS.call(v) === '[object File]' || toS.call(v) === '[object Blob]' ? v : encode(v) arr.push(encode(k) + '=' + v) } diff --git a/src/next.js b/src/next.js index a0936c1..49ce53d 100644 --- a/src/next.js +++ b/src/next.js @@ -104,7 +104,10 @@ class _Request { } } else { for (let k in options.body) { - if (toS.call(options.body[k]) === '[object File]') { + if ( + toS.call(options.body[k]) === '[object File]' || + toS.call(options.body[k]) === '[object Blob]' + ) { hasAttach = true break }