【发布时间】:2013-06-19 21:23:51
【问题描述】:
UPD:这是我的implemented solution to this problem
我正在尝试通过 Azure.Storage 库(不是 REST API)上传到 Azure blob 存储并通过共享访问密钥进行身份验证。
我已经看到了这个blog post,但是自从发布之后 API 发生了变化,现在我无法得到相同的结果。
这是我所拥有的:
var blobClient = new CloudBlobClient(new Uri(blobWithSas.BaseUri), new StorageCredentials(blobWithSas.Sas));
// here I receive 404 error
var blob = blobClient.GetBlobReferenceFromServer(new Uri(blobWithSas.AbsoluteUri));
using (var stream = new FileStream(fullFilePath, FileMode.Open))
{
blob.UploadFromStream(stream);
}
有:
blobWithSas.BaseUri = http://127.0.0.1:10000/devstoreaccount1/a6dc9274-6ce1-4095-be6b-e84d1012cb24(Guid 是容器的名称,已经存在,在其他地方创建。)
blobWithSas.Sas = ?sv=2012-02-12&se=2013-06-23T03%3A04%3A53Z&sr=b&sp=w&sig=NaMqgXRMXDFvLAp8LTskgplAKp%2B9LCZzq8WK9Zo35x8%3D(也在代码的其他地方发布)
blobWithSas.AbsoluteUri = http://127.0.0.1:10000/devstoreaccount1/a6dc9274-6ce1-4095-be6b-e84d1012cb24/foldername/filename.txt
blob 不存在,我想上传新文件并创建一个 blob。我有“服务器”应用程序持有 Azure 存储帐户的访问密钥。服务器将向客户端发出 SAS,客户端将文件直接上传到 Azure。所以 SAS 只会写入,不会读取,客户端将在服务器告诉它们的位置创建文件(容器、文件夹名称)
GetBlobReferenceFromServer 出现问题 - 我从 Azure 存储收到 404 错误。是的,blob 不存在,也没有参考。那么给定 CloudBlobClient,我如何将文件上传到 blob?
附言我意识到这些东西有 REST API。但我之前使用过Microsoft.WindowsAzure.Storage 库,如果可能的话,我想避免使用 REST 服务。
【问题讨论】:
标签: c# azure azure-storage azure-blob-storage