给定uri在C#中失败时从blob下载 [英] download from blob when given its uri fails in c#
本文介绍了给定uri在C#中失败时从blob下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从Azure blob下载文件并将其保存在本地,但是似乎失败了. 这是相关的代码:
I'm trying to download a file from Azure blob and save it locally, but it seems to fail. Here's the relevant code:
var blobClientCode = client.CreateCloudBlobClient();
string codeUri = "https://???.blob.core.windows.net/...../mycode.exe";
using (var codeContent = File.OpenWrite("C:\\code.exe")) {
blobClientCode.GetBlockBlobReference(codeUri).DownloadToStream(codeContent);
}
我收到一个错误,其中该容器不存在.我在做什么错了?
I get an error in which the container doens't exist. What am I doing wrong?
推荐答案
首先尝试获取对容器的引用,然后仅使用相对路径从中定义CloudBlockBlob.
Try getting a reference to the container first then defining the CloudBlockBlob from this using just the relative path.
这是对我有用的代码:
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("myContainerName");
CloudBlockBlob blockBlob = container.GetBlockBlobReference("/subfolder/filename.exe");
using (fileStream == System.IO.File.OpenWrite("C:\code.exe")) {
blockBlob.DownloadToStream(fileStream);
}
这篇关于给定uri在C#中失败时从blob下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文