使用wx.uploadFile上传图片,图片已经上传到云储存,但是在上传到数据库时少上传了图片路径?
发布于 4 年前 作者 wujie 7596 次浏览 来自 问答


 let that=this

  const {eid,ename,keshi,wtdetail,UpLoadImgs,chooseImgs}=that.data

  const db = wx.cloud.database()


chooseImgs.forEach((v,i)=>{

 

    wx.cloud.uploadFile({

      cloudPath:new Date().getTime()+'.png', // 上传至云端的路径

        filePath: v, // 小程序临时文件路径

        

        success: res => {

          // 返回文件 ID

          console.log("上传成功",res)

          //获取文件路径

          that.data.UpLoadImgs.push(res.fileID)

          console.log(UpLoadImgs)

          

          if(i===chooseImgs.length-1){

          db.collection('problemdetail').add ({

    

            data:{

              

              gh:eid,

              xm:ename,

              ks:keshi,

              wtxq:wtdetail,

              tupian:UpLoadImgs

              // date:Y+'年'+M+'月'+D+'日'

            },

            success:res=>{

              

          

              wx.showToast({

                

                title: '提交成功',

                mask:true,

                duration:2000

              })

            //  that.setData({

            //   eid:[],

            //   ename:[],

            //   keshi:[],

            //   wtdetail:[],

            //   chooseImgs:[],  

            //   UpLoadImgs:[]

            //  })

              

            },

            

            fail: err => {

              wx.showToast({

                icon: 'none',

                title: '提交失败'

              })


            }

        })

        }

        },


    })


这个的问题是图片已经全部上传到存储里面了,UpLoadImgs数组也是获取到了上传的图片的全部路径,但是在上传多张图片的时侯,路径在上传到数据库是会缺失



2 回复

tupian:UpLoadImgs 这里的 UpLoadImgs 似乎没有定义

你的console.log(UpLoadImgs)输出的是啥?

回到顶部