微信小程序 wx.uploadFile在安卓手机上面the same task is working问题解决
2016-12-14 09:57
1021 查看
微信小程序 wx.uploadFile在安卓手机上面the same task is working问题解决
微信小程序上传图片的时候,如果是多图片上传,一般都是直接用一个循环进行wx.uploadFile
这个在电脑上面测试与苹果手机上面都不会有什么问题
但当用安卓测试的时候,你会发现小程序会提示一个the same task is working
wx.uploadFile不能并行,因为wx.uploadFile是一个异步函数,所以循环的时候在安卓手机上会出现并行
解决的方法
做一个上传完的标识,然后
用递归算法进行上传
在上传成功的回调函数里面,直接递归,标识满足直接跳出,完成所有图片上传
贴上个代码段
//上传标识 var i=0 //imglist为要上传图片的路径数组 uploadImg: function () { var that = this if (i == imglist.length) { //清空还原 news = "" city = "" i=0 wait = true imglist = [] serverImg = [] retrunList = [] that.setData({ loding: false, src: [], disabled: false }) return; } var imgcount = imglist.length; wx.uploadFile({ url: config.serverUrl('index.php/user/uploadtu'), filePath: imglist[i], name: 'file', formData: { 'user': 'test' }, success: function (res) { serverImg.push(res.data) if (imgcount == serverImg.length) { var serverImgStr = serverImg.join("|") wx.request({ url: config.serverUrl('index.php/user/baobeiadd'), method: 'POST', data: Util.json2Form({ imglist: serverImgStr, userId: userId, news: news, city: city, latitude: latitude, longitude: longitude }), header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res2) { if (res2.data.state == "ok") { that.setData({ loding: false, butTxt: "发布", disabled: false }) Util.mesUrl("发布成功!", "../index/index") } else { Util.mes("描述至少10人字以上哦,还有图片也要选哦!") } } }) }else { //这里直接递归 i++; that.uploadImg(); } }, fail: function (e) { console.log(e) Util.mes("图片上传失败,请重新发布!" + i) } }) },
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
您可能感兴趣的文章:
相关文章推荐
- 微信小程序之wx.request:fail错误,真机预览请求无效问题解决,安卓,ios网络预览异常
- 微信小程序 wx.uploadFile无法上传解决办法
- genymotion the file is corrupt 无法下载手机虚拟机问题解决办法
- 微信小程序之wx.request:fail错误,真机预览请求无效问题解决,安卓,ios网络预览异常(转)
- PHP--解决微信小程序上传图片(wx.uploadFile)接口代码
- genymotion the file is corrupt 无法下载手机虚拟机问题解决办法
- 文件系统不同步问题resource is out of sync with the file system的解决办法
- xx is not in the sudoers file 问题解决
- MyEclipse:Resource is out of sync with the file system问题的解决办法
- Resource is out of sync with the file system问题解决方法
- xx is not in the sudoers file 问题解决【转载】
- sudo问题解决 用户名is not in the sudoers file
- xx is not in the sudoers file 问题解决
- xx is not in the sudoers file 问题解决
- *** is not in the sudoers file 问题解决
- 【QA4】【sudoers问题解决】(*** is not in the sudoers file.This incident will be reported)
- PHPExcel的exception 'Exception' with message 'The filename is not recognised as an OLE file问题解决
- 【转】如何在fedora等Linux系统下解决(** is not in the sudoers file)的问题
- 文件系统不同步问题resource is out of sync with the file system的解决办法
- eclipse 文件系统不同步问题resource is out of sync with the file system的解决办法