收藏
回答

使用小程序 云开发 用真机调试 上传图片自动压缩 怎么解决?

使用小程序 云开发   用真机调试 上传手机端照片发现在云存储的图片都被自动压缩了 几M的图片都变成100多k了 求大神解决!

代码:

async upImg(event) {

    try {

      const result = await wx.chooseImage({

        count: 0,

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

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

      })

      // console.log(result)

      const imgNameEnd = result.tempFilePaths[0].split('.')

      const imgName = Date.now() + '.' + imgNameEnd[imgNameEnd.length - 1]

      console.log(imgName)

      const upResult = await this.upFile(result.tempFilePaths[0], imgName)

      console.log(upResult)

      this.setData({

        img: upResult.fileID

      })

    } catch (error) {

      console.error('图片选择失败!' + error)

    }

  },

  async upFile(imgUrl, imgName) {

    try {

      return await wx.cloud.uploadFile({

        cloudPath: 'img/' + imgName,

        filePath: imgUrl

      })

    } catch (error) {

      console.error('图片上传失败' + error)

    }

  },

回答关注问题邀请回答
收藏
登录 后发表内容
问题标签