0
votes

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.

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:

    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. https://azuresdkdocs.blob.core.windows.net/$web/javascript/azure-arm-storage/11.0.0/interfaces/blobserviceproperties.html#cors

1
Here is what setServiceProperites does : azuresdkdocs.blob.core.windows.net/$web/javascript/…ibnawfi

1 Answers

0
votes

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