我在azure blob中存储图像,我想在UI上显示图像,但我想将我的img标签与blob uri绑定。 如何绑定< img>带有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");
}
}
这是我的索引:
< img src =" @ Url.Action(" myAction"," Home",new {path = ViewBag.path})" />
我正在尝试评论的部分,即搜索将uri传递给img标签的方式......但没有得到任何地方......所以请帮忙,我必须在我的控制器中做出什么改变以及在我的索引中获得所需的结果。
答案 0 :(得分:3)
如果您已将图像保存在blobstorage中,则可以从
访问该图像http://<storage-account-name>.blob.core.windows.net/<container-name>/<blob-name>
修改您的操作方法,以返回一个字符串,并将该网址作为其值。
另外,请确保您的存储帐户已设置为公共访问权限。
有关使用Azure Blob存储的更多详细信息,请参阅以下内容: