gpt4 book ai didi

c# - Azure 存储私有(private)容器 blob 到 MemoryStream

转载 作者:行者123 更新时间:2023-11-30 13:30:37 31 4
gpt4 key购买 nike

我正在兜圈子,试图找出将文件从 Azure 存储私有(private)容器下载到 MemoryStream 的代码。

到目前为止我已经有了......

StorageCredentials storageCredentials = new StorageCredentials(*my StorageAccountName*, *my StorageAccountAccessKey*);
CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);

Uri blobUri = new Uri(featureFile.URL);
CloudBlockBlob blob = new CloudBlockBlob(blobUri);

MemoryStream mem = new MemoryStream();
blob.DownloadToStream(mem);

最后一行出错...

The remote server returned an error: (404) Not Found.

但是,当容器不是私有(private)的时,它会正常工作而不会出现错误。

非常感谢任何帮助,谢谢。

最佳答案

请尝试以下代码:

StorageCredentials storageCredentials = new StorageCredentials(*my StorageAccountName*, *my StorageAccountAccessKey*);
CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);

Uri blobUri = new Uri(featureFile.URL);
CloudBlockBlob blob = new CloudBlockBlob(blobUri, storageCredentials);//added storageCredentials

MemoryStream mem = new MemoryStream();
blob.DownloadToStream(mem);

由于容器具有Private ACL,因此需要对请求进行身份验证。使用this CloudBlockBlob 的构造函数负责处理这个问题。

关于c# - Azure 存储私有(private)容器 blob 到 MemoryStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31566314/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com