我想獲取單個blob的共享訪問簽名,然後使用REST API下載blob。但是,我總是得到一個禁止的403錯誤消息。無論是在存儲模擬器還是雲端。這裏是我的代碼:Windows Azure共享訪問簽名總是給出:Forbidden 403
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("myConnectionStringHere...");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("containerName");
CloudBlob blob = container.GetBlobReference("blobName");
string sasToken = blob.GetSharedAccessSignature(new SharedAccessPolicy()
{
Permissions = SharedAccessPermission.Read,
SharedAccessExpiryTime = DateTime.UtcNow + TimeSpan.FromHours(24)
}
);
string completeUri = string.Format(CultureInfo.InvariantCulture, "{0}{1}", blob.Uri, sasToken);
// now use the uri to make the rest call and download
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(completeUri);
request.Method = "GET";
using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
{
using (Stream s = resp.GetResponseStream())
{
using (FileStream fs = new FileStream("test.jpg", FileMode.Create, FileAccess.Write))
{
byte[] buffer = new byte[8 * 1024];
int len;
while ((len = s.Read(buffer, 0, buffer.Length)) > 0)
{
fs.Write(buffer, 0, len);
}
}
}
}
調用GetResponse的時候我不斷收到403錯誤。任何幫助感謝!
編輯:忘了提:我使用的是最新的蔚藍SDK(2.0)
編輯2:我嘗試了很多,發現了一個名爲Azure的管理Studio工具。該工具能夠創建SAS令牌。我做到了,並將其與我的REST調用代碼一起使用。這工作得很好,所以錯誤必須在我寫的令牌創建代碼中。但是,sas字符串的格式完全相同。我不知道還有什麼嘗試
你能提供一個你會使用的blob和容器名稱的例子嗎? –
容器名稱:「cname」 blob名稱:「bname」 – Christian
查看我的一些代碼,我使用:blob.Uri.AbsoluteUri + sasToken作爲url。 –