【发布时间】:2015-12-10 04:39:06
【问题描述】:
所以我有一个 asp.net 网络表单应用程序,它有很多图像要显示在每个页面中。在上传这些图像的同时将它们存储到数据库中。在迁移到云端之前,我曾经检查文件系统是否存在图像,如果存在,我会获取并显示它,否则我会在文件系统中创建图像然后使用它。现在我想将此应用程序移动到云并实现类似的逻辑,唯一的区别是我保存到 azure blob 存储帐户并从那里获取图像的文件系统。下面给出的代码用于从 blob 存储上传和获取图像
CloudBlobContainer BlobContainer = Img.GetCloudBlobContainer();
CloudBlockBlob blob = BlobContainer.GetBlockBlobReference(picture_id + "_HighRes.Jpeg");
var blobs = BlobContainer.ListBlobs(picture_id + "_HighRes.Jpeg");
if (blobs.Count()>0)
{
foreach (var i in blobs)
{
Picture_name = i.Uri.ToString();
}
}
else
{
SqlConnection Db_Con = new SqlConnection(ConfigurationManager.ConnectionStrings["DB_connection"].ToString());
DataSet ds_pic = new DataSet();
Db_Con.Open();
SqlDataAdapter sd_pic = new SqlDataAdapter("select PictureBinary FROM Picture where Id=" + pic_id, Db_Con);
sd_pic.Fill(ds_pic);
Db_Con.Close();
byte[] picbin = (byte[])ds_pic.Tables[0].Rows[0][0];
ImageConverter ic = new ImageConverter();
System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(picbin);
//img.Save(HttpContext.Current.Server.MapPath(imagePath + picture_id + ".Jpeg"), System.Drawing.Imaging.ImageFormat.Jpeg);
System.Drawing.Image img4 = null;
// VariousQuality(img, picture_id, 200, "_HighRes.Jpeg");
// Picture_name = imagePath + picture_id + "_HighRes.Jpeg";
BlobContainer = Img.GetCloudBlobContainer();
blob = BlobContainer.GetBlockBlobReference(picture_id + "_HighRes.Jpeg");
blob.UploadFromStream(new MemoryStream(picbin));
blobs = BlobContainer.ListBlobs(picture_id + "_HighRes.Jpeg");
foreach (var i in blobs)
{
Picture_name = i.Uri.ToString();
}
return Picture_name;
现在这可行,但您可以想象该网站非常慢。有没有更好的方法来处理云中的图像
【问题讨论】:
标签: asp.net azure azure-blob-storage