nomo998
nomo998
  • 发布:2020-09-03 10:16
  • 更新:2020-10-20 12:35
  • 阅读:1020

【报Bug】uni.savefile 循环保存多图总会有失败的

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

HBuilderX类型: 正式

HBuilderX版本号: 2.8.8

手机系统: iOS

手机系统版本号: iOS 13.4

手机厂商: 苹果

手机机型: 7P

页面类型: vue

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

ChooseMedia() {//添加照片
let _that = this;
uni.chooseImage({
count: 8, //默认9
sizeType: ['original', 'compressed'],
success: (res) => {
//console.log(res)
//console.log(this.memIndex)

                    if (this.imgList.length != 0) {  
                        this.imgList = this.imgList.concat(res.tempFiles);  
                        this.imgPath = this.imgPath.concat(res.tempFilePaths)  
                    } else {  
                        //this.imgList = res.tempFilePaths;  
                        this.imgList = res.tempFiles;  
                        this.imgPath = res.tempFilePaths;  
                    }  

                    // #ifndef H5  
                          var tempFilePaths = res.tempFilePaths;  

                          var imgLen = tempFilePaths.length;  
                          //     imgxx = [];  
                          // //console.log(res.tempFilePaths)  
                          console.log(tempFilePaths)  
                           for(let i=0;i<imgLen;i++){  
                               console.log(i)  
                               uni.saveFile({  
                                 tempFilePath: tempFilePaths[i],  
                                 success: function (res) {  
                                    //var savedFilePath = res.savedFilePath;  
                                  //imgxx.push(res.savedFilePath);  
                                  console.log(res)  
                                 },fail(e) {  
                                    console.log(e)  
                                 }  
                               });  

                           }  

                    // #endif  

                }  
            });  
        },

操作步骤:

上传两张以上图片必现

预期结果:

上传多张能100% 保存到本地

实际结果:

上传超过两张以上图片 总有几张上传失败

bug描述:

uni.saveFile 循环保存多图的时候 总有那么几张会失败,{"errMsg":"saveFile:fail 保存文件[_doc/uniapp_temp_1599097921427/compressed/1599097968412.jpg] copyTo 失败:无效的修改"} 尝试值保存1张或两张几乎都能成功,超过2张就会有失败的

2020-09-03 10:16 负责人:无 分享
已邀请:
我这头像像骷髅

我这头像像骷髅 - 一个资深的前端HTML网页复制架构师

for 循环里用立即执行方法试试?

  • nomo998 (作者)

    还是不行的

    2020-09-03 10:57

  • 5***@qq.com

    回复 nomo998: 我也碰到了这个问题请问解决了吗,我加了promise,还是有失败的

    2020-09-09 09:37

  • nomo998 (作者)

    回复 5***@qq.com: 没有呢,直接不用了,目前没有找到解决方法呢

    2020-09-09 14:49

  • 5***@qq.com

    回复 nomo998: 我搞定了用递归,失败了就重新保存知道保存为止

    2020-09-10 14:56

  • nomo998 (作者)

    回复 5***@qq.com: 兄tie 加个扣 指导一下395534391 感恩

    2020-09-11 21:04

  • DCloud_UNI_GSQ

    回复 5***@qq.com: 使用promise的话,串行应该也可以避免

    2020-10-10 17:11

DCloud_UNI_GSQ

DCloud_UNI_GSQ

HX 2.9.2 + 已修复此问题

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