收藏
回答

小程序使用wx.chooseImage选择本地图片上传的问题

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.chooseImage 微信iOS客户端 8.0.10 2.9.5

复现步骤:选择图片->代开本地图片,不勾选对号,点击图片放大预览->点击完成!我没勾选图片却上传了,勾选后取消也是如此!

 takephoto: function () {
    wx.chooseImage({
      count: 9 - this.data.renderImgList.length,
      sizeType: ['compressed'],
      sourceType: ['album', 'camera'],
      success: (res) => {
        const tempFilePaths = res.tempFilePaths;
        const tempFiles = res.tempFiles;
        // 循环查看上传的图片大小,有超过20M的就直接返回并弹窗提示
        for (let inta = 0; inta < tempFiles.length; inta++) {
          const size = (res.tempFiles[inta].size) / 1024 / 1024;
          if (size > 20) {
            wx.showToast({
              icon: 'none',
              title: '图片大于20M,无法显示及保存',
              mask: true
            });
            return;
          }
          // 获取图片的path
          const imgPath = res.tempFiles[inta].path;
          // 获取最后一个.的位置
          const index = imgPath.lastIndexOf('.');
          // 获取后缀,转成小写
          const ext = imgPath.substr(index + 1).toLowerCase();
          if (ext === 'gif') {
            wx.showToast({
              icon: 'none',
              title: '暂不支持上传动图',
              mask: true
            });
            return;
          }
        }
        wx.showLoading({
          title: '加载中',
          mask: true
        });
        this.setData({
          imgList: []
        });
        for (let i = 0, fileLen = tempFilePaths.length; i < fileLen; i++) {
          this.uploadtoServer(tempFilePaths[i], fileLen, i);
        }
      }
    });
  },
最后一次编辑于  2021-08-18
回答关注问题邀请回答
收藏

3 个回答

登录 后发表内容