收藏
回答

wx.cloud.uploadFile上传图片到云存储为什么不行?

模板那里可以的,一摸一样复制过来就不行了 求教哪里不对?

 doUpload: function () {

    // 选择图片

    wx.chooseImage({

      count: 1,

      sizeType: ['compressed'],

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

      success: function (res) {

        wx.showLoading({

          title: '上传中',

        })


        const filePath = res.tempFilePaths[0]

        

        // 上传图片

        const cloudPath = `my-image${filePath.match(/\.[^.]+?$/)[0]}`

        wx.cloud.uploadFile({

          cloudPath,

          filePath,

          success: res => {

            console.log('[上传文件] 成功:', res)


            // app.globalData.fileID = res.fileID

            // app.globalData.cloudPath = cloudPath

            // app.globalData.imagePath = filePath

            

            // wx.navigateTo({

            //   url: '../storageConsole/storageConsole'

            // })

          },

          // fail: e => {

          //   console.error('[上传文件] 失败:', e)

          //   wx.showToast({

          //     icon: 'none',

          //     title: '上传失败',

          //   })

          // },

          complete: () => {

            wx.hideLoading()

          }

        })

      },

      // fail: e => {

      //   console.error(e)

      // }

    })

  },


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

1 个回答

  • 工作号
    工作号
    2021-03-03

    报错信息贴一下啊

    2021-03-03
    有用
    回复 2
    • 风之羽
      风之羽
      01-23
      (in promise) MiniProgramError
      errCode: -1 | errMsg: status 403, error: <?xml version='1.0' encoding='utf-8' ?><Error> <Code>SignatureDoesNotMatch</Code> <Message>The Signature you specified is invalid.</Message> <StringToSign>sha11642906066;164290696661e9fb07bd9c0bac43505ae02b891548e917f91b</StringToSign> <FormatString>post/6131-a18875319967-2gjkmtfp29d8017f-1302510359/xueyuan/10:47:45 GMT 0800 (CST)</FormatString> <Resource>cos.ap-shanghai.myqcloud.com/6131-a18875319967-2gjkmtfp29d8017f-1302510359/xueyuan/10:47:45 GMT+0800 (CST)</Resource> <RequestId>NjFlY2MxZDNfNDUyOTY5NjRfZjE0Ml8xMTU5NjA0</RequestId> <TraceId>OGVmYzZiMmQzYjA2OWNhODk0NTRkMTBiOWVmMDAxODc0OWRkZjk0ZDM1NmI1M2E2MTRlY2MzZDhmNmI5MWI1OTczMmZiNDZmZjBmNTVjMGU4NTViNDhhYWVjNzNkNzI4MDc2ZjE0YWQwYWM5NWQ0Yzk2MDQyNDVlYmNhNDMyZTI=</TraceId></Error>;
      Error: errCode: -1 | errMsg: status 403, error: <?xml version='1.0' encoding='utf-8' ?><Error> <Code>SignatureDoesNotMatch</Code> <Message>The Signature you specified is invalid.</Message> <StringToSign>sha11642906066;164290696661e9fb07bd9c0bac43505ae02b891548e917f91b</StringToSign> <FormatString>post/6131-a18875319967-2gjkmtfp29d8017f-1302510359/xueyuan/10:47:45 GMT 0800 (CST)</FormatString> <Resource>cos.ap-shanghai.myqcloud.com/6131-a18875319967-2gjkmtfp29d8017f-1302510359/xueyuan/10:47:45 GMT+0800 (CST)</Resource> <RequestId>NjFlY2MxZDNfNDUyOTY5NjRfZjE0Ml8xMTU5NjA0</RequestId> <TraceId>OGVmYzZiMmQzYjA2OWNhODk0NTRkMTBiOWVmMDAxODc0OWRkZjk0ZDM1NmI1M2E2MTRlY2MzZDhmNmI5MWI1OTczMmZiNDZmZjBmNTVjMGU4NTViNDhhYWVjNzNkNzI4MDc2ZjE0YWQwYWM5NWQ0Yzk2MDQyNDVlYmNhNDMyZTI=</TraceId></Error>;
      at new t (WASubContext.js:17:6017)
      at Function.success (WASubContext.js:17:179244)
      at d (WASubContext.js:2:113669)
      at at (WASubContext.js:2:114494)
      at f (WASubContext.js:26:12355)
      at Function.<anonymous> (WASubContext.js:26:272520)
      at d (WASubContext.js:2:113669)
      at at (WASubContext.js:2:114494)
      at at (WASubContext.js:26:217158)
      at Set.forEach (<anonymous>)
      01-23
      回复
    • 风之羽
      风之羽
      01-23回复风之羽
      开发工具中能上传,预览就不行
      01-23
      回复
登录 后发表内容
问题标签