h***@163.com
h***@163.com
  • 发布:2020-11-12 13:33
  • 更新:2021-07-09 11:43
  • 阅读:883

uni fileupload真机调试报错

分类:HBuilderX

上传文件代码

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>)

请问是什么原因导致的?谢谢

2020-11-12 13:33 负责人:无 分享
已邀请:
xBug

xBug

uni.chooseImage 返回的File对象结构跟 uni.uploadFile 需要的file对象结构不一样,要先转换一下。

uni.chooseImage

uni.uploadFile

该问题目前已经被锁定, 无法添加新回复