美文网首页
31.选择图片上传到云存储

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

作者: 陈情令 | 来源:发表于2021-09-02 11:44 被阅读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)

      }

    })

  },

相关文章

网友评论

      本文标题:31.选择图片上传到云存储

      本文链接:https://www.haomeiwen.com/subject/yqvfpltx.html