【发布时间】:2020-09-05 17:05:42
【问题描述】:
我正在尝试从 Azure 中的私有存储容器获取 Blob 流。我从几个地方在互联网上得到了一些帮助来提出这个功能:
/// <summary>
/// Get a blob out of storage.
/// HEAVILY Based on Code from:
/// https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-customer-provided-key
/// </summary>
/// <param name="iSA">Name of storage account</param>
/// <param name="iSA_Key">Key for the storage account</param>
/// <param name="iContainerName">Name of the container</param>
/// <param name="iBlobName">Name of Blob to Get</param>
/// <returns>
/// A stream of the Blob
/// </returns>
public Stream getBlob(
String iSA, String iSA_Key, String iContainerName,
String iBlobName)
{
Uri accountUri = new Uri("https://" + iSA + ".blob.core.windows.net");
// https://stackoverflow.com/questions/16072709/converting-string-to-byte-array-in-c-sharp
byte[] key = Encoding.ASCII.GetBytes(iSA_Key);
// Specify the customer-provided key on the options for the client.
BlobClientOptions options = new BlobClientOptions()
{
CustomerProvidedKey = new CustomerProvidedKey(key)
};
// Create a client object for the Blob service, including options.
BlobServiceClient serviceClient = new BlobServiceClient(accountUri,
new DefaultAzureCredential(), options);
// Create a client object for the container.
// The container client retains the credential and client options.
BlobContainerClient containerClient = serviceClient.GetBlobContainerClient(iContainerName);
// Create a new block blob client object.
// The blob client retains the credential and client options.
BlobClient blobClient = containerClient.GetBlobClient(iBlobName);
Azure.Response<BlobDownloadInfo> myAR = blobClient.Download();
BlobDownloadInfo BDI = myAR.Value;
return BDI.Content;
}
不幸的是,当我调用 blobClient.Download() 时出现以下错误:
Azure.RequestFailedException: 'This request is not authorized to perform this operation using this permission...'
有什么简单的方法可以解决吗?
AFAIK:我将正确的参数传递给函数...
【问题讨论】:
-
我引用的微软文章似乎是关于加密密钥的。也许与存储密钥无关......