[英]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.