收藏
回答

关于文件上传wx.uploadFile的用法?

for(var i=0;i<len;i++){
          var $path=$files[i].path;
          wx.uploadFile({
            url:app.globalData.api+"&r=util.uploader.upload&file=file",
            filePath:$path,
            name:"file",//规定的key值
            header: {
              "Content-Type""multipart/form-data"
            },
            success:function(res){
              console.log(JSON.parse(res.data));
              console.log(JSON.parse(res.data).files[0].url)
              console.log(JSON.parse(res.data).files[0].filename)
              successNum++;
              console.log(successNum)
              arr.push({
                url:JSON.parse(res.data).files[0].url,
                filename:JSON.parse(res.data).files[0].filename
              });
              console.log(arr.length);
              console.log(arr)
              if(arr.length==successNum){
                console.log(that.data.id)
                o.post("member/cart/addsd",{
                  id:that.data.id,//会员id
                  files:arr,//文件列表
                  title:that.data.id.title,//原产品详情
                  gid:that.data.gid,//原产品id
                },function(res){
                  console.log(res);
                  if(res==1){
                    wx.switchTab({
                      url:"/pages/member/cart/index"
                    });
                  }
                })
                
                /*
                wx.navigateTo({
                  url:"/pages/member/cart/index?id="+that.data.id
                })
                */
              }else{
                console.log("没有上传完成")
              }
            }
          })
        };

d我现在要上传多个文件,但是wx.uploadFile  api只能上传一个文件,于是我便用了循环上传写法,但是实际操作中,比如上传两张图片,第一张图片会自动多上传一次
 咋处理
回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容
问题标签