收藏
回答

为什么在开发者工具中选择图片后,显示路径不存在无法上传?

    wx.chooseMedia({
      count: remain,
      mediaType: ['image'],
      sourceType: ['album', 'camera'],
      sizeType: ['compressed'],
      success: async (res) => {
        const files = res.tempFiles || [];
        if (!files.length) return;
        wx.showLoading({ title: '上传中...', mask: true });
        try {
          for (let i = 0; i < files.length; i += 1) {
            if (this.data.attachmentFileIds.length >= this.data.maxFiles) break;
            const file = files[i];
            if (!file || !file.tempFilePath) continue;
            const filename = this.buildImageUploadName(file, i);
            const contentType = this.resolveImageContentType(filename);
            try {
              await this.uploadAttachmentByPath(
                file.tempFilePath,
                filename,
                contentType,
                Number(file.size) || 0,
                false
              );
            } catch (err) {
              console.error('反馈图片上传失败:', err);
            }
          }
        } finally {
          wx.hideLoading();
        }
      },
      fail: (err) => {
        console.error('选择图片失败:', err);
        wx.showToast({ title: (err && err.errMsg) || '选择图片失败', icon: 'none' });
      }
    });

真机可以正常上传,但是在开发者工具中会报错

反馈图片上传失败: Error: readFile:fail http://tmp/2IKzHfoM9nrg2d7aa79b32c8270dc0733b24828732ae.jpg not found
at toUploadError (upload.js:57)
at _callee$ (upload.js:170)
at s (regeneratorRuntime.js?forceSync=true:1)
at Generator.<anonymous> (regeneratorRuntime.js?forceSync=true:1)
at Generator.throw (regeneratorRuntime.js?forceSync=true:1)
at asyncGeneratorStep (asyncToGenerator.js?forceSync=true:1)
at i (asyncToGenerator.js?forceSync=true:1)(env: Windows,mp,2.01.2510260; lib: 3.15.0)

我在开发者工具中打开这个临时路径,图片也是存在的

求大神解答

回答关注问题邀请回答
收藏

1 个回答

  • 启年
    启年
    06-16

    上传图片,为什么错误信息里边包含 readFile 呢?


    用什么版本的开发者工具,试试i最新的稳定版的,看看效果。

    06-16
    有用 2
    回复 2
    • 骥骐
      骥骐
      06-16
      非常感谢,重新安装了开发者工具就好了!之前各种改代码丝毫没想到是软件的问题
      06-16
      回复
    • 启年
      启年
      06-16回复骥骐
      哈,代码写好了,工具里边先测试,不行就上真机,一切以真机为准, 工具有问题就换个新版本,哈哈哈
      06-16
      1
      回复
登录 后发表内容