如果我将图像存储在我的blob中,如何将html的<img/>标记与blob uri绑定以在ui上显示图像?

时间:2016-02-09 05:37:28

标签: image asp.net-mvc-4 azure razor

我在azure blob中存储图像,我想在UI上显示图像,但我想将我的img标签与blob uri绑定。 如何绑定&lt; img&gt;带有blob uri的html标签在UI上显示图像?

这是我的控制器...

public class HomeController : Controller
{

    public ActionResult Index()
    {
        ViewBag.path = @"F:\download_button_small2.png";
        return View();
    }

    public FileContentResult myAction(string path)
    {        
        string fileName = Path.GetFileNameWithoutExtension(path);
        byte[] imageInBytes = System.IO.File.ReadAllBytes(path);
        //upload image to blob and URL in table
        ImageContainer img = new ImageContainer();
        string imageUri = img.insert(fileName, imageInBytes);
        //returns back the image uri from Blob Storage            
        return new FileContentResult(imageInBytes, "image/png");
    }      
}

这是我的索引:

&lt; img src =&#34; @ Url.Action(&#34; myAction&#34;,&#34; Home&#34;,new {path = ViewBag.path})&#34; /&GT;

我正在尝试评论的部分,即搜索将uri传递给img标签的方式......但没有得到任何地方......所以请帮忙,我必须在我的控制器中做出什么改变以及在我的索引中获得所需的结果。

1 个答案:

答案 0 :(得分:3)

如果您已将图像保存在blobstorage中,则可以从

访问该图像
http://<storage-account-name>.blob.core.windows.net/<container-name>/<blob-name>  

修改您的操作方法,以返回一个字符串,并将该网址作为其值。

另外,请确保您的存储帐户已设置为公共访问权限。

有关使用Azure Blob存储的更多详细信息,请参阅以下内容:

Get started with Azure Blob storage using .NET

Azure Bits #2 – Saving The Image To Azure Blob Storage