收藏
回答

cannot upload file to the Cloud Base?

We are using TCB (云开发) on our Mini Program. Our architecture requires make an external HTTP request and upload file to the TCB storage. I've been following official doc(https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/uploadFile.html), however getting 405 Method Not Allowed error after receiving upload URL. Can you help me to solve it?

Always get an error:

<?xml version='1.0' encoding='utf-8' ?>

<Error>

<Code>MethodNotAllowed</Code>

<Message>The specified method is not allowed against this resource.</Message>

<Resource>cos.ap-shanghai.myqcloud.com/7472-travl4good-test-ps8fl-1302595888/file.txt</Resource>

<RequestId>NWY2OTE4OWJfNmMxZTFkMDlfNjA1Y185MzJjNzk=</RequestId>

<TraceId>OGVmYzZiMmQzYjA2OWNhODk0NTRkMTBiOWVmMDAxODc0OWRkZjk0ZDM1NmI1M2E2MTRlY2MzZDhmNmI5MWI1OWE4OGMxZjNjY2JiNTBmMTVmMWY1MzAzYzkyZGQ2ZWM4OWM4Y2M5MzI5ZmUzN2FjZDk1OTRjYWI5Yjg5OTJlZDA=</TraceId>

</Error>


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

3 个回答

  • 古月
    古月
    2021-07-02

    分享一下,看能帮助其它人吗,同样MethodNotAllowed错误,我发现不是服务器端问题,而是的客户端平台问题。我用的字节跳动的小程序平台:

    data:是https://api.weixin.qq.com/tcb/uploadfile?access_token返回值

    fileinfo:是tt.chooseImage后再tt.getImageInfo值

    部分代码如下,核心思想是不能用tt.request方法,而是要用字节带的tt.uploadFile方法,就解决了,代码如下:

       const fileSystemManager = tt.getFileSystemManager();

            var filedata = fileSystemManager.readFileSync(fileinfo.path"base64");

      tt.uploadFile({

                url: data.url,

                filePath: fileinfo.path,

                contentType: "multipart/form-data; charset=utf-8; boundary=__X_PAW_BOUNDARY__",

                name: "file",

                formData: {

                    "Signature": data.authorization,

                    "key": filepath,

                    "x-cos-security-token": data.token,

                    "x-cos-meta-fileid": data.cos_file_id,

                    "file": {

                        value: filedata,

                        options: {

                            filename: filename,

                            contentType: fileinfo.type

                        }

                    }

                },

                success(res) {

                    console.log("uploadfile 调用成功"res);

                    // if (res.data.errcode != 0) {

                    //     reject(res.data);

                    // } else {

                    resolve(res);

                    // }

                },

                fail(err) {

                    console.log("uploadfile 调用失败:"err);

                    reject(err);

                }

            })


    2021-07-02
    有用
    回复
  • MGee
    MGee
    2021-05-02

    能发帖求助的肯定找了很久问题,我是这个问题我觉得很隐蔽了,这个解决了就上传成功了,特意来回复下!contentType后要带上 boundary=---XXXXXX

    就是这样:

    contentType":"multipart/form-data; boundary=---------------------------7db1851cd1158",


    2021-05-02
    有用
    回复
  • 哄哄
    哄哄
    2020-09-22

    If you have the correct permissions, but you're not using an identity that belongs to the bucket owner's account, COS returns MethodNotAllowed.

    2020-09-22
    有用
    回复 2
    • Vitale
      Vitale
      发表于移动端
      2020-09-22
      Do you have any suggestions how I can solve it?
      2020-09-22
      回复
    • Yun
      Yun
      2021-03-13回复Vitale
      can try to set  'content-length' into headers
      2021-03-13
      回复
登录 后发表内容
问题标签