分享一下,看能帮助其它人吗,同样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); } })
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> [图片] [图片]
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); } })
HTTP API上传图片 最后一步返回这个错误 什么意思啊?[图片] HTTP API上传图片 最后一步返回这个错误 什么意思啊 <?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/7765-weimin-s5l9y-1302279841/index</Resource> <RequestId>NWYxZDY4MDZfMmY5ZDA4MDlfODAwNF8xNmFiNzUy</RequestId> <TraceId>OGVmYzZiMmQzYjA2OWNhODk0NTRkMTBiOWVmMDAxODc0OWRkZjk0ZDM1NmI1M2E2MTRlY2MzZDhmNmI5MWI1OTczMmZiNDZmZjBmNTVjMGU4NTViNDhhYWVjNzNkNzI4YTVkZGJiNmM4OGZlNjMyYjJlZDA4ODBhZDdlNjY0YjY=</TraceId> </Error>
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); } })
HTTP API上传图片问题?app.post("/uploadfile", upload.single("file"), (req, res) => { var file =req.file promise.then(data => { url = 'https://api.weixin.qq.com/tcb/uploadfile?access_token=' + JSON.parse(data).access_token data = { "env": 'laoqi-2gvugolvf7a76b77', "path": 'demo/'+ file.originalname } getData(url, data).then(dataa => { var res = dataa if (res.errmsg == 'ok') { requestData = { 'key': 'demo/'+ file.originalname, 'Signature': res['authorization'], 'x-cos-security-token': res['token'], 'x-cos-meta-fileid': res['cos_file_id'], 'file':{ value:fs.createReadStream(file.path), options:{ 'filename': file.originalname, 'contentType': file.mimetype } } } getData(res['url'], requestData).then(data2 => { console.log(data2) // res.send(data2) }).catch(err => { console.log(err) res.send(err) }) } }).catch(err => { console.log(err) res.send(err) }) }).catch(data => { console.log(data); }) }) 一直报错 <?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/6c61-laoqi-2gvugolvf7a76b77-1304583758/demo/QQ图片20200711091851.jpg</Res ource> <RequestId>NWZlOTdkYzBfN2QzZjIyMDlfODQyYl8xY2RiY2Zj</RequestId> <TraceId>OGVmYzZiMmQzYjA2OWNhODk0NTRkMTBiOWVmMDAxODc0OWRkZjk0ZDM1NmI1M2E2MTRlY2MzZDhmNmI5MWI1OTczMmZiNDZmZjBmNTV jMGU4NTViNDhhYWVjNzNkNzI4NWM1YTFlYWZiODhiYTgwMjZhMzcyMjBmNWVlZTMzNjI=</TraceId> </Error>
2021-07-02