ali-sdk / ali-oss

Aliyun OSS(Object Storage Service) JavaScript SDK for the Browser and Node.js
https://www.alibabacloud.com/help/doc-detail/52834.htm
MIT License
1.94k stars 578 forks source link

Cannot read property 'x-oss-request-id' of undefined #632

Closed halegreen closed 5 years ago

halegreen commented 5 years ago

使用sdk遇到这个问题,版本6.1.1,似乎是返回的response没有x-oss-request-id这个字段?求解答

client.put('image', new Buffer('test content')).then((result) => {
            console.log(result);
        });
Uncaught (in promise) TypeError: Cannot read property 'x-oss-request-id' of undefined
    at Client.requestError$ (http://127.0.0.1:53025/index.worker.js?t=1559197800782:2893:43)
    at tryCatch (http://127.0.0.1:53025/index.worker.js?t=1559197800782:17446:40)
    at Generator.invoke [as _invoke] (http://127.0.0.1:53025/index.worker.js?t=1559197800782:17680:22)
    at Generator.prototype.(anonymous function) [as next] (http://127.0.0.1:53025/index.worker.js?t=1559197800782:17498:21)
    at tryCatch (http://127.0.0.1:53025/index.worker.js?t=1559197800782:17446:40)
    at invoke (http://127.0.0.1:53025/index.worker.js?t=1559197800782:17536:20)
    at http://127.0.0.1:53025/index.worker.js?t=1559197800782:17579:11
    at new Promise (<anonymous>)
    at callInvokeWithMethodAndArg (http://127.0.0.1:53025/index.worker.js?t=1559197800782:17578:16)
    at AsyncIterator.enqueue [as _invoke] (http://127.0.0.1:53025/index.worker.js?t=1559197800782:17601:13)
Ari1c commented 5 years ago

你是指你打印的result中没有x-oss-request-id字段?(ps:我试的结果res.headers里有x-oss-request-id字段)

halegreen commented 5 years ago

@Ari1c 不是result,没有打印出result,是oss sdk里面报的错,是sdk解析response的时候没有x-oss-request-id字段

Ari1c commented 5 years ago

你有在里面的example跑一下吗

halegreen commented 5 years ago

@Ari1c 这个sdk只有在chrome端才能用吗,我的client是支付宝小程序

Ari1c commented 5 years ago

也不是啊,高版本浏览器都是可以的啊,小程序暂时只支持直传,https://help.aliyun.com/document_detail/92883.html?spm=a2c4g.11186623.6.1269.354460casu6Ll9

Ari1c commented 5 years ago

image 你在控制台check一下跨域配置里headers有配置x-oss-request-id字段

halegreen commented 5 years ago

@Ari1c 跨域设置加了的,还是不行。 另外小程序暂时只支持直传的例子:https://help.aliyun.com/document_detail/92883.html?spm=a2c4g.11186623.6.1269.354460casu6Ll9 适用于支付宝小程序么?

my.chooseImage({
      chooseImage: 1,
      success: res => {
        const path = res.apFilePaths[0];
        console.log(path)
        var key = 'image.jpg'
        my.uploadFile({
            url: 'https://ocr-image-bucket.oss-cn-shanghai.aliyuncs.com', //ocr image bucket host
            fileType: 'image',
            fileName: key,
            filePath: path,
            formData: {
                name: path,
                key: '${filename}',
                policy: '<my-policy>',
                OSSAccessKeyId: '<my-OSSAccessKeyId>',
                success_action_status: '200',
                signature: '<my-signature>'
            },
            success: (res) => {
              my.alert({ content: 'success info: ' + res.data });
            },
        });
});

我这边也试了下支付宝小程序直传这个方式,oss返回400: 我明明只选择了一个图片上传,并没有多个,不知道啥问题?

<?xml version="1.0" encoding="UTF-8"?>
<Error>
  <Code>IncorrectNumberOfFilesInPOSTRequest</Code>
  <Message>POST requires exactly one file upload per request.</Message>
  <RequestId>5CF091D883464DAC560BBF9B</RequestId>
  <HostId>ocr-image-bucket.oss-cn-shanghai.aliyuncs.com</HostId>
</Error>
richard1122 commented 5 years ago

在云函数里面用 putStream 也遇到了一样的报错,执行环境是阿里云的香港 node8 云函数

Ari1c commented 5 years ago

@ZoeShaw101 小程序直传你要保证你的bucket是读写权限的(但不建议),不是读写权限的话是要设置policy,ak,signature的

Ari1c commented 5 years ago

@ZoeShaw101 https://help.aliyun.com/document_detail/127260.html?spm=a2c4g.11186623.6.1487.24483ccc3q7qLh 这是支付宝小程序的情况

Ari1c commented 5 years ago

@richard1122 你能描述具体点吗,也是在小程序中使用我们的sdk是吗(小程序目前支持直传)

richard1122 commented 5 years ago

@Ari1c 是在云函数里直接 put stream 时候传一个 node 的 buffer

Ari1c commented 5 years ago

@richard1122 你的bucket有设置跨域规则(x-oss-request-id字段),或者把报错信息解一下图

shadow88sky commented 5 years ago

我也遇到同样的错误,node端 流式上传文件,报这个错误 image image

shadow88sky commented 5 years ago

如果是读取本地文件上传 则正常

shadow88sky commented 5 years ago

进去调试 ,里面报 image

hainee commented 1 year ago

到现在任然在报错