上传文件代码
uni.chooseImage({
count: 3, // 允许选3
sizeType: ['original'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['camera','album'], //从相册选择
success: function (res) {
let files = res.tempFiles
files.forEach(item =>{
uni.showToast({
title:'开始上传',
icon:'none'
})
uni.uploadFile({
url: 'http://xxx.udms.xxx.com/api/app/file/v1/uploa',
file: item,
classification: 'msbt',
name:'myfile',
header:{
'accept': 'application/json',
'X-Api-Authorization': wx.getStorageSync('token'),
'x-request-sys': 'sysweb'
},
success:function(r){
console.log(r)
let _res = JSON.parse(r.data)
if(_res.code == 200){
self.uploadImages.push({
url: _res.data.filePath,
name: _res.data.fileId
})
}
}
})
})
}
})
在浏览器上传正常,在pda设备(android6)中报错,
TypeError: Cannot read property 'indexOf' of undefined
at wr ()
at
at createUploadTask ()
at rc ()
at uploadFile ()
at
at D ()
at Object.Hu.<computed>.Gu.<computed> [as uploadFile] ()
at eval (binning.js:53)
at Array.forEach (<anonymous>)
请问是什么原因导致的?谢谢
1 个回复
xBug
uni.chooseImage 返回的File对象结构跟 uni.uploadFile 需要的file对象结构不一样,要先转换一下。
uni.chooseImage
uni.uploadFile