附件判断增加Blob类型

master
yutent 2023-02-17 11:00:40 +08:00
parent 0735b4452d
commit 7983cb0b16
4 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@bytedo/fetch", "name": "@bytedo/fetch",
"version": "2.1.1", "version": "2.1.2",
"description": "全新的ajax封装。分2个版本, 一个基于XMLHttpRequest, 一个基于window.fetch", "description": "全新的ajax封装。分2个版本, 一个基于XMLHttpRequest, 一个基于window.fetch",
"main": "dist/index.js", "main": "dist/index.js",
"files": [ "files": [

View File

@ -127,7 +127,10 @@ class _Request {
params = options.body params = options.body
} else { } else {
for (let k in options.body) { 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 hasAttach = true
break break
} }

View File

@ -15,7 +15,7 @@ export const decode = decodeURIComponent
function serialize(p, obj, query) { function serialize(p, obj, query) {
var k var k
if (Array.isArray(obj)) { if (Array.isArray(obj)) {
obj.forEach(function(it, i) { obj.forEach(function (it, i) {
k = p ? `${p}[${Array.isArray(it) ? i : ''}]` : i k = p ? `${p}[${Array.isArray(it) ? i : ''}]` : i
if (typeof it === 'object') { if (typeof it === 'object') {
serialize(k, it, query) serialize(k, it, query)
@ -84,7 +84,7 @@ export const Format = {
for (let i in data) { for (let i in data) {
let el = data[i] let el = data[i]
if (Array.isArray(el)) { if (Array.isArray(el)) {
el.forEach(function(it) { el.forEach(function (it) {
form.append(i + '[]', it) form.append(i + '[]', it)
}) })
} else { } else {
@ -99,13 +99,13 @@ export const Format = {
} }
let arr = [] let arr = []
let query = function(k, v) { let query = function (k, v) {
if (/native code/.test(v)) { if (/native code/.test(v)) {
return return
} }
v = typeof v === 'function' ? v() : v 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) arr.push(encode(k) + '=' + v)
} }

View File

@ -104,7 +104,10 @@ class _Request {
} }
} else { } else {
for (let k in options.body) { 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 hasAttach = true
break break
} }