wx.cloud.uploadFile上传的图片不是你选中的图片!!!
发布于 5 年前 作者 jie08 7358 次浏览 来自 问答

选择好图片上传后,在云后台的图片不是我选择的图片,请官方测试一下你们提供的DEMO

// 上传图片

  doUpload: function () {

    // 选择图片

    wx.chooseImage({

      count: 1,

      sizeType: [‘compressed’],

      sourceType: [‘album’, ‘camera’],

      success: function (res) {

        wx.showLoading({

          title: ‘上传中’,

        })

        const filePath = res.tempFilePaths[0]

 

        // 上传图片

        const cloudPath = ‘my-image’ + filePath.match(/\.[^.]+?$/)[0]

        wx.cloud.uploadFile({

          cloudPath,

          filePath,

          success: res => {

            console.log(’[上传文件] 成功:’, res)

            app.globalData.fileID = res.fileID

            app.globalData.cloudPath = cloudPath

            app.globalData.imagePath = filePath

            this.setData({

              text: ‘changed data’

            })

           // wx.navigateTo({

            //  url: ‘…/storageConsole/storageConsole’

           // })

          },

          fail: e => {

            console.error(’[上传文件] 失败:’, e)

            wx.showToast({

              icon: ‘none’,

              title: ‘上传失败’,

            })

          },

          complete: () => {

            wx.hideLoading()

          }

        })

      },

      fail: e => {

        console.error(e)

      }

    })

  },

3 回复

你也可以试试,我就是用官方的demo试的,你也可以试试,是你进入到云里面的存储可以看到的,不是你上传的那张照片,你试试就知道了。

你把这句取消注释就可以了

可能你看到的图片有缓存,或者是后台返回给你的图片地址错误。

回到顶部