如何从网站源代码访问存储在azure blob中的图像 [英] How do I access image stored in azure blob from website source code

查看:110
本文介绍了如何从网站源代码访问存储在azure blob中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆图像存储为Azure存储中的blob

我还有一个网站(托管在azure上,但(我认为)无关紧要)

我最简单的方法是在网站上将图片显示为图片标记的一部分。

我想限制自己使用Azure提供的服务。



截至目前我可以想到这个解决方案

1)在WCF服务中托管Rest API,这个Rest API将返回一个图像

2)可以在图片标签内提供其余API的网址。



这是最好的方法吗?



注意,我现在并不关心性能或可伸缩性。我只是想让这个工作。

解决方案

hi
AmitDey,



你可以azure blob服务可以作为URI链接访问,你可以直接访问

1)只需将blob保护模式从私有移到公共,以便你可以访问它们。

2 )Azure blob服务作为服务提供给PUBLIC作为REST服务,因此您的应用程序也不应该面临任何类型的设备问题



如果你很好的去这些标准然后使用下面的代码从 blockBlob 获取引用URI



 //检索存储帐户来自连接字符串。 
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting(StorageConnectionString));

//创建blob客户端。
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

//检索对先前创建的容器的引用。
CloudBlobContainer container = blobClient.GetContainerReference(mycontainer);

//检索对名为photo1.jpg的blob的引用。
CloudBlockBlob blockBlob = container.GetBlockBlobReference(photo1.jpg);







谢谢你


I have a bunch of images stored as blobs in Azure Storage
I also have a website ( hosted on azure, but (i think) that is irrelevant)
What is the easiest way for me to show that Image on the website as part of an Image tag.
I would like to limit myself to services offered by Azure.

As of now I can think of this solution
1) Host a Rest API within a WCF Service,This Rest API will return an image
2) A url to the rest API can be provided from within the image tag.

Is this the best way to do it ?

Note, I do not care so much about performance or scalability right now. I just want to get this working.

解决方案

hi AmitDey,

You can azure blob services can be accessed as an URI LINKS you can directly access
1) Just remove the blob protection mode from private to public so that you can access them.
2) Azure blob services are given out as service to PUBLIC as REST services so your application should not face issue with any kind of devices too

if you are good to go with these criterias then use the below code to get the rerence URI from "blockBlob "

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString"));

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

// Retrieve reference to a blob named "photo1.jpg".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("photo1.jpg");




thanks you


这篇关于如何从网站源代码访问存储在azure blob中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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