UPD:这是我的implemented solution to this problem上传到Azure的Blob存储与共享访问密钥
我试图通过Azure.Storage库上传到Azure的Blob存储(未REST API),并通过共享访问密码验证。
我已经看到这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);
}
有:(GUID是容器的名称,已经存在,创建别处)
blobWithSas.BaseUri
= http://127.0.0.1:10000/devstoreaccount1/a6dc9274-6ce1-4095-be6b-e84d1012cb24
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?
p.s.我意识到有这些东西的REST API。但是我之前使用过Microsoft.WindowsAzure.Storage
库,如果可能的话,我想避免使用REST服务。
谢谢!你是明星!我错过了用SAS创建容器对象。 – trailmax
我发现queryString是URL编码的,而blobContainerSasUri不是,这使得Substring调用不能正常工作。将该行替换为'string blobContainerUri = blobContainerSasUri.Split('?')[0];' – tster