31.选择图片上传到云存储

2021-09-02  本文已影响0人  陈情令

如果报错:upload.js? [sm]:46 上传失败 Error: errCode: -503002 storage permission denie

修改一下储存权限

代码:

  chooseImg() {

    wx.chooseImage({

      count: 1,

      // 选择图片的数量

      sizeType: ['original', 'compressed'],

      sourceType: ['album', 'camera'],

      success: res => {

        // tempFilePath可以作为img标签的src属性显示图片

        // const tempFilePaths = res.tempFilePaths,

        this.uploadImg(res.tempFilePaths[0])

      }

    })

  },

  uploadImg(temFile) {

    wx.cloud.uploadFile({

      cloudPath: "我是图片.jpg",

      filePath: temFile,

      success: res => {

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

      },

      fail(err) {

        console.log("上传失败",err)

      }

    })

  },

上一篇 下一篇

猜你喜欢

热点阅读