我正在尝试使用以下代码从Asp.Net Core中的azure blob下载图像。但我得到了
“不支持给定路径的格式”
我的代码:
StorageCredentials creds = new StorageCredentials(accountName, accountKey);
CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
CloudBlobClient client = account.CreateCloudBlobClient();
container = client.GetContainerReference(blobName);
//下载
public async void DownloadAsync(string path, string[] names)
{
string MyPath = path.Replace("https://browsercontent.blob.core.windows.net/blob1/", "");
CloudBlockBlob blockBlob = container.GetBlockBlobReference(MyPath+names[0]);
path = path + names[0];
await blockBlob.DownloadToFileAsync(path, FileMode.Create);
}
如何解决此问题?
答案 0 :(得分:1)
第一个参数DownloadToFileAsync
to是磁盘上文件的路径,它应该是一个本地路径,如" C:\ Temp \ 3.png"例如。见下面的例子:
public async void DownloadAsync(string path, string[] names)
{
string MyPath = path.Replace("https://browsercontent.blob.core.windows.net/blob1/", "");
CloudBlockBlob blockBlob = container.GetBlockBlobReference(MyPath+names[0]);
var localPath = @"C:\Temp" + names[0];
await blockBlob.DownloadToFileAsync(localPath , FileMode.Create);
}
其他一些提示:
async void
。返回public async TaskDownloadAsync(string path, string[] names)
之类的任务,以便等待该方法