收藏
回答

使用wx.uploadFile上传图片,图片已经上传到云储存,但是在上传到数据库时少上传了图片路径?


 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数组也是获取到了上传的图片的全部路径,但是在上传多张图片的时侯,路径在上传到数据库是会缺失



最后一次编辑于  2020-06-29
回答关注问题邀请回答
收藏

2 个回答

  • z.song
    z.song
    2020-06-29

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

    2020-06-29
    有用
    回复 3
    • 廿三丶
      廿三丶
      2020-06-29
      定义的,存放路径的一个数组
      2020-06-29
      回复
    • z.song
      z.song
      2020-06-29回复廿三丶
      tupian:UpLoadImgs 改成 that.data.UpLoadImgs试试呢
      2020-06-29
      回复
    • 廿三丶
      廿三丶
      2020-06-29回复z.song
      一样的,都是会缺失
      2020-06-29
      回复
  • 白宦成 #Linux中国
    白宦成 #Linux中国
    2020-06-29

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

    2020-06-29
    有用
    回复 3
    • 廿三丶
      廿三丶
      2020-06-29
      有的,在data里面定义,这是一个数组,存放 上传的到云存储里的路径数据
      2020-06-29
      回复
    • 白宦成 #Linux中国
      白宦成 #Linux中国
      2020-06-29回复廿三丶
      那你可能要填的是 this.data.uploadImgs
      2020-06-29
      回复
    • 廿三丶
      廿三丶
      2020-06-29回复白宦成 #Linux中国
      这样子改了,也解决不了问题
      2020-06-29
      回复
登录 后发表内容
问题标签