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.95k stars 576 forks source link

list接口不能直接在浏览器端调用吗? #1180

Open yionr opened 1 year ago

yionr commented 1 year ago

根据官方文档:https://help.aliyun.com/document_detail/383987.html 我发现调用await client.list(); 时,console报错error: %j TypeError: Cannot read properties of null (reading 'Contents') 对应在项目源码中lib/browser/object.js:186的位置:

  const result = await this.request(params);
  let objects = result.data.Contents || [];

我看了一下开发控制台中的响应数据是包含我需要的数据的(XML格式),但是不知道为什么似乎代码内没有将XML顺利转成JSON,导致后续result.data是null。 为了一开始方便, 我并没有使用STS,而是直接建立了一个RAM,不知道这是否会有影响?最后附上我完整的代码:

const client = new OSS({
  region: '-',
  accessKeyId: '-',
  accessKeySecret: '-',
  bucket: '-'
})
export const listDir = async () => {
  try {
    await client.list()
  } catch (e) {
    console.log(e);
  }
}
listDir()
Mask1210 commented 1 year ago

我也碰到同样的问题了,楼主解决了吗