【发布时间】:2014-02-25 23:14:06
【问题描述】:
关于将图像文件上传到 azure blob 的教程有很多,我已成功将图像文件上传到 blob 容器,现在我的问题是如何获取它,这是我的代码:
var bitmapImage = new BitmapImage();
bitmapImage.UriSource = new Uri("http://sweetapp.blob.core.windows.net/userprofiles/"+imagename,UriKind.RelativeOrAbsolute);
imgProf.Source = bitmapImage;
我做错了吗?还是在显示之前我需要做些什么?任何答案将不胜感激!
更新:
这是对我有用的代码
上传:
var credentials = new StorageCredentials("sweetapp","[my key]");
var client = new CloudBlobClient(new Uri("http://sweetapp.blob.core.windows.net/"), credentials);
var container = client.GetContainerReference("userprofiles");
await container.CreateIfNotExistsAsync();
var perm = new BlobContainerPermissions();
perm.PublicAccess = BlobContainerPublicAccessType.Blob;
var blockBlob = container.GetBlockBlobReference(imgName);
using (var fileStream = await file.OpenSequentialReadAsync())
{
await blockBlob.UploadFromStreamAsync(fileStream);
}
获取图片:
var bitmapImage = new BitmapImage();
bitmapImage.UriSource = new Uri("http://sweetapp.blob.core.windows.net/userprofiles/"+imagename,UriKind.RelativeOrAbsolute);
imgProf.Source = bitmapImage;
【问题讨论】:
-
这种方法对我来说很合适。你遇到什么问题了吗?
-
是的,图像没有显示,但是当我看到我的 blob 时。但是当我尝试直接查看它时,例如:sweetapp.blob.core.windows.net/userprofiles/killingZ.png 发生了一些错误,我做错了吗?顺便说一句,我已经更新了问题
-
你忘记了
await container.SetPermissionsAsync(perm);var blockBlob = container.GetBlockBlobReference(imgName);之前的代码行。
标签: c# xaml azure microsoft-metro