获取图像在Azure Blob存储 [英] Getting images in the Azure Blob Storage

查看:194
本文介绍了获取图像在Azure Blob存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关于上传影像文件到蔚蓝色斑点这么多的教程,我已经成功上传图像文件到一个blob容器,现在我的问题是如何得到它,这是我的code:

  VAR的BitmapImage =新的BitmapImage();
bitmapImage.UriSource =新的URI(http://sweetapp.blob.core.windows.net/userprofiles/+ imagename,UriKind.RelativeOrAbsolute);
imgProf.Source = BitmapImage的;

我做错了?或者是,我需要显示它之前做一些事情?任何答案将AP preciated!

更新:

这是code为我工作

上传

  VAR证书=新StorageCredentials(sweetapp,[我的钥匙]);
            VAR的客户=新CloudBlobClient(新的URI(http://sweetapp.blob.core.windows.net/),证书);
            变种容器= client.GetContainerReference(的UserProfiles);
            等待container.CreateIfNotExistsAsync();
            VAR烫发=新BlobContainerPermissions();
            perm.PublicAccess = BlobContainerPublicAccessType.Blob;
            VAR blockBlob = container.GetBlockBlobReference(imgName);
            使用(VAR FILESTREAM =等待file.OpenSequentialReadAsync())
            {
            等待blockBlob.UploadFromStreamAsync(FILESTREAM);
           }

获取图像:

  VAR的BitmapImage =新的BitmapImage();
     bitmapImage.UriSource =新的URI(http://sweetapp.blob.core.windows.net/userprofiles/+ imagename,UriKind.RelativeOrAbsolute);
     imgProf.Source = BitmapImage的;


解决方案

请查看 ACL 的BLOB容器上。我相信你得到的错误是因为容器的ACL设置为私人(这是默认的ACL)。为了您的code以上的工作,容器的访问级别应该是的Blob 集装箱。你会发现这个链接有用的理解上的blob容器各种ACL选项: HTTP: //msdn.microsoft.com/en-us/library/windowsazure/dd179354.aspx

尝试下面的code获取/设置容器的ACL:

  storageAccount =新CloudStorageAccount(新StorageCredentials(ACCOUNTNAME,accountkey),FALSE);
    变种容器= storageAccount.CreateCloudBlobClient()GetContainerReference(容器名称);
    //获取容器权限
    VAR的权限= container.GetPermissions();
    Console.WriteLine(容器的ACL是:+ permissions.PublicAccess);
    //设置容器权限BLOB
    container.SetPermissions(新BlobContainerPermissions()
    {
        PublicAccess = BlobContainerPublicAccessType.Blob,
    });

there are so many tutorials regarding uploading image files to the azure blob, i have successfully uploaded image file to a blob container and now my problem is how to get it, here is my code:

var bitmapImage = new BitmapImage();
bitmapImage.UriSource = new Uri("http://sweetapp.blob.core.windows.net/userprofiles/"+imagename,UriKind.RelativeOrAbsolute);
imgProf.Source = bitmapImage;

am I doing it wrong? or is something that i need to do before displaying it? any answers will be appreciated!

Update:

this is the code that worked for me

Upload:

            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);
           }

Getting the image:

     var bitmapImage = new BitmapImage();
     bitmapImage.UriSource = new Uri("http://sweetapp.blob.core.windows.net/userprofiles/"+imagename,UriKind.RelativeOrAbsolute);
     imgProf.Source = bitmapImage;

解决方案

Please check the ACL on the blob container. I believe the error you're getting is because the container's ACL is set as Private (which is the default ACL). For your code above to work, the container's access level should be either Blob or Container. You may find this link useful for understanding various ACL options on blob containers: http://msdn.microsoft.com/en-us/library/windowsazure/dd179354.aspx.

Try the code below to get/set container's ACL:

    storageAccount = new CloudStorageAccount(new StorageCredentials("accountname", "accountkey"), false);
    var container = storageAccount.CreateCloudBlobClient().GetContainerReference("containername");
    //Get the container permission
    var permissions = container.GetPermissions();
    Console.WriteLine("Container's ACL is: " + permissions.PublicAccess);
    //Set the container permission to Blob
    container.SetPermissions(new BlobContainerPermissions()
    {
        PublicAccess = BlobContainerPublicAccessType.Blob,
    });

这篇关于获取图像在Azure Blob存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆