简体   繁体   English

如何使用 @azure/arm-storage nodejs 将 cors 添加到 Blob 容器

[英]How do I add cors to a Blob Container using @azure/arm-storage nodejs

So, I've been tinkering for a while now and I've been struggling with adding cors to my Blob Containers in Azure using the @azure/arm-storage nodejs package.因此,我已经修修补补了一段时间,并且一直在努力使用 @azure/arm-storage nodejs 包将 cors 添加到 Azure 中的 Blob 容器。

Anyone got a clue how to set service properties?有人知道如何设置服务属性吗?

Here is what I got:这是我得到的:

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

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

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

cors look like this: cors 看起来像这样:

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

At this point I'm just mashing things together but I don't know what I'm doing wrong.在这一点上,我只是把东西混在一起,但我不知道我做错了什么。

Here is their documentation if you want to get a better understanding of how the BlobServices class works.如果您想更好地了解 BlobServices 类的工作原理,请参阅他们的文档。 https://azuresdkdocs.blob.core.windows.net/$web/javascript/azure-arm-storage/11.0.0/interfaces/blobserviceproperties.html#cors https://azuresdkdocs.blob.core.windows.net/$web/javascript/azure-arm-storage/11.0.0/interfaces/blobserviceproperties.html#cors

So I figured it out ... Not the best documentation but after a couple tries here is what I got:所以我想通了......不是最好的文档,但经过几次尝试后,我得到了:

  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);
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何删除Blob存储容器天蓝色NodeJS - how to delete blob storage container azure NodeJS 如何使用@azure/storage-blob sdk append 一个 blob 文件? (NodeJS) - How do I append a blob file using @azure/storage-blob sdk ? (NodeJS) 使用 nodejs 在 SDK v10 中获取 sasQueryParameter 后,如何将文件上传到 Azure 存储 blob 容器? - how to upload a file to Azure storage blob Container after getting sasQueryParameter in SDK v10 using nodejs? 如何使用Node设置Azure Blob存储CORS属性? - How to set Azure Blob Storage CORS properties using Node? Azure Webapp(使用Node.js)记录到Blob存储 - Azure Webapp (using Nodejs) logging to Blob storage 如何使用 NodeJS 在 web 应用程序中从 Azure blob 存储中提供 HTML 文件? - How can I serve an HTML file from Azure blob storage in a web app using NodeJS? (Azure 存储 - nodeJS)获取应用于 blob 容器和队列的 SAS 策略 - (Azure Storage - nodeJS) Getting SAS policies that are applied on blob container and queue 如何使用 nodejs 在 azure blob 存储上设置 contenttype - How to set contenttype on azure blob storage with nodejs NodeJS '@azure/storage-blob':上传文件时如何设置 Blob 服务属性 - NodeJS '@azure/storage-blob': How do set Blob Service Properties when uploading a file 如何从私有 Azure Blob 存储容器中删除 Blob - How to Delete Blob From Private Azure Blob Storage Container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM