【问题标题】:How do I add cors to a Blob Container using @azure/arm-storage nodejs如何使用 @azure/arm-storage nodejs 将 cors 添加到 Blob 容器
【发布时间】:2020-11-05 03:44:28
【问题描述】:

所以,我一直在修补一段时间,一直在努力使用 @azure/arm-storage nodejs 包将 cors 添加到 Azure 中的 Blob 容器。

有人知道如何设置服务属性吗?

这是我得到的:

  async setCorsOnResource(storageAccountName, cors) {
    try {
      const service = await this.createBlobServicesManager();

      service.setServiceProperties(this.resourceName, storageAccountName, cors);

    } catch (err) {
      console.error(err);
    }
  }

cors 看起来像这样:

    const cors = {
      CorsRule: [{
        AllowedOrigins: ['*'],
        AllowedMethods: ['GET'],
        AllowedHeaders: [],
        ExposedHeaders: [],
        MaxAgeInSeconds: 60
      }],
    };

在这一点上,我只是把事情混在一起,但我不知道我做错了什么。

如果您想更好地了解 BlobServices 类的工作原理,这里是他们的文档。 https://azuresdkdocs.blob.core.windows.net/$web/javascript/azure-arm-storage/11.0.0/interfaces/blobserviceproperties.html#cors

【问题讨论】:

标签: node.js azure


【解决方案1】:

所以我想通了...不是最好的文档,但经过几次尝试后,我得到了:

  async setCorsOnResource(storageAccountName, cors) {
    try {
      const service = await this.createBlobServicesManager();

      const response = await service.setServiceProperties(this.resourceName, storageAccountName, {
        cors: {
          corsRules: [{
            allowedHeaders: ['*'],
            allowedMethods: ['GET'],
            allowedOrigins: ['*'],
            exposedHeaders: ['*'],
            maxAgeInSeconds: 3600,
          }],
        },
      });
      console.log(response);

    } catch (err) {
      console.error(err);
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 2014-02-10
    • 2017-11-24
    • 2014-04-12
    • 2017-05-20
    • 2022-11-02
    相关资源
    最近更新 更多