不能以编程方式设置权限的blob容器Azure存储

不能以编程方式设置权限的blob容器Azure存储

本文介绍了不能以编程方式设置权限的blob容器Azure存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建具有一个blob容器后CreateIfNotExists(),我立即拨打 SetPermissions()来允许用户公开访问到容器中的斑点,但不是在容器本身

After creating a blob container with CreateIfNotExists(), I immediately call SetPermissions() to allow users public access to the blobs in the container, but not to the container itself.

像这样:

CloudBlobContainer pdfContainer = blobClient.GetContainerReference(ContainerName.PDFs);

if (pdfContainer.CreateIfNotExists())
    pdfContainer.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });

创建成功的容器,但是当我登录到Azure的门户网站,BLOB容器权限私人

我缺少一个额外的调用commit的权限更改?那我已经看了例子无似乎表明,我没有看到文档中的任何事。我使用的Azure的SDK的2.0版。

Am I missing an additional call to commit the permission changes? None of the examples that I've looked at seem to show that and I don't see anything in the documentation either. I'm using v2.0 of the Azure SDK.

更新:

看起来 CreateIfNotExists()总是返回false。我撬开在反射器打开组装和发现它受凉(409)冲突HTTP错误和吞咽异常。这似乎是与任一SDK或服务器端REST实现的问题。即使容器不存在和容器创建成功,一个409仍从服务器返回

It looks like CreateIfNotExists() is always returning false. I pried the assembly open in Reflector and found that it was catching a (409) Conflict HTTP error and swallowing the exception. This appears to be an issue with either the SDK or the server-side REST implementation. Even though the container does not exist and the container creation succeeds, a 409 is still returned from the server.

这似乎是做的最好的事就是调用 CreateIfNotExists()并忽略返回值了。

It seems like the best thing to do is call CreateIfNotExists() and ignore the return value for now.

此外,没有必要调用 SetPermissions之前调用 GetPermissions()()

Also, it is not necessary to call GetPermissions() before calling SetPermissions().

推荐答案

这工作对我来说(我的应用程序运行它启动时):

This works for me (I run it on app start-up):

var blobContainer = GetPhotoBlobContainer();
blobContainer.CreateIfNotExists();
var perm = new BlobContainerPermissions();
perm.PublicAccess = BlobContainerPublicAccessType.Blob;
blobContainer.SetPermissions(perm);

这篇关于不能以编程方式设置权限的blob容器Azure存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 20:41