c# - 无法使用 DownloadToFileAsync 方法 C# 下载块 Blob
问题描述
我正在尝试使用 C# 从 Azure 下载块 blob。我正在使用的代码如下。
在其他测试中,我能够列出容器中的 blob,但无法下载特定的 blob。它没有给我异常或错误,但是在本地创建的文件是空的。
出于明显的原因,我已经清除了连接字符串。
我的代码看起来没问题吗?
var containerName = "samples-workitems";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=xxxxxxxxxxxxxxxxxx.windows.net");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(containerName);
try {
CloudBlockBlob blockBlob = container.GetBlockBlobReference("file.png");
var localPath = string.Format("C:\\users\\user\\downloads\\file.png");
blockBlob.DownloadToFileAsync(localPath, FileMode.Create);
catch
{
}
解决方案
你知道吗 - 从昨天开始我一直坚持这个问题,自从 2 分钟前发布这个 - 我删除了......
CloudBlockBlob blockBlob = container.GetBlockBlobReference("file.png");
var localPath = string.Format("C:\\users\\user\\downloads\\file.png");
try 语句中的这两行代码并将它们放在它上面。现在可以用了?!
这是为什么?
推荐阅读
- mongodb - 无法识别的表达式“$first”
- python - 如何根据最接近的匹配有效地替换大型数据帧(100k+ 行)中的值?
- reactjs - 如何使用 React.memo 优化性能
- visual-studio - 如何在 Azure 管道中模拟 Visual Studio 网站的发布操作
- javascript - 对象数组中的函数未处理并作为字符串 JS 返回
- python - Python/Pandas:添加具有当前时间戳的字段(epoch/unix)
- sql - BigQuery - 根据另一列中的值选择列的最小值
- quickfixn - 向预告片添加字段会改变校验和位置 - quickfix C# - #quickfixn
- php - 在 beforeSave() 和停止 save() 调用上从 CakePHP 3.8 模型返回自定义 422 实体错误的正确方法是什么?
- forms - TYPO3 8 form - 定义几个文件上传文件夹