[英]Azure Blob Storage - Changing permissions of a container and accessing with SAS
我有一個Azure Blob
容器,其中包含一些Blob。 使用以下代碼成功創建了容器:
if (container.CreateIfNotExists())
{
var permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Off;
container.SetPermissions(permissions);
}
您將看到權限設置為私有(即, PublicAccess
為Off
)。
在我的代碼的后半部分,我想使用SAS
打開權限,有效期為1 hour
。 為此,我使用了以下代碼:
if (container.Exists())
{
//Set the expiry time and permissions for the container.
//In this case no start time is specified, so the shared access signature becomes valid immediately.
SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1);
sasConstraints.Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.List;
//Generate the shared access signature on the container, setting the constraints directly on the signature.
string sasContainerToken = container.GetSharedAccessSignature(sasConstraints);
//Return the URI string for the container, including the SAS token.
return container.Uri + sasContainerToken;
}
但是,無論如何調整形狀,當我將瀏覽器導航到返回的URL(即container.Uri + sasContainerToken
)時,都會收到身份驗證錯誤:
<Error>
<Code>AuthenticationFailed</Code>
<Message>
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:d7f89ef3-919b-4b86-9b4f-4a95273c20ff Time:2014-06-26T15:33:11.2754096Z
</Message>
<AuthenticationErrorDetail>
Signature did not match. String to sign used was rl 2014-06-26T16:32:02Z /mycontainer/$root 2014-02-14
</AuthenticationErrorDetail>
</Error>
誰能給我任何指示我為什么看到此身份驗證錯誤的指針?
我的最終網址看起來像是正確的格式嗎?:
https://myservice.blob.core.windows.net/mycontainer?sv=2014-02-14&sr=c&sig=0MSvKIRJnxWr2G%2Bh0mj%2BslbNtZM3VnjSF8KPhBKCPs8%3D&se=2014-06-26T16%3A32%3A02Z&sp=rl
我很茫然,所以任何指針將不勝感激。
我也面臨着完全相同的錯誤:)。 您不能使用共享訪問簽名執行與容器相關的操作(列出Blob除外)。 您將需要使用帳戶密鑰對容器執行操作。 從此頁上: http : //msdn.microsoft.com/zh-cn/library/azure/jj721951.aspx
使用共享訪問簽名的受支持的操作包括:
讀寫頁面或塊Blob內容,塊列表,屬性和元數據
刪除,租賃和創建Blob的快照
列出容器中的斑點
更新
對於列出Blob,只需將&comp=list&restype=container
到您的URL中,就可以解決問題。 因此,您的網址應為:
https://myservice.blob.core.windows.net/mycontainer?sv=2014-02-14&sr=c&sig=0MSvKIRJnxWr2G%2Bh0mj%2BslbNtZM3VnjSF8KPhBKCPs8%3D&se=2014-06-26T16%3A32%3A02Z&sp=rl&comp=list&restype=container
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.