I'm currently running a site of a dedicated server but want to scale up using Microsofts Azure cloud platform in the future but im unsure if a certin part of my code will work on azure.
The site consists of a gallery of items with an image for each item. The images are stored in a sqlserver database.
I have created a http handler that caches the images to disk and redirects the request to the image (as shown at the end of the post).
The images are saved into a virtual directory called "imagecache" inside my ASP.NET application. (i.e. ~/imagecache/ ).
As the web app will run in many virtual machine instances on the Azure platform the images will need to be shared between the instances right?
So my question really is.. What is the best way of achieving what I already have on that is compatible wit azure?
Thanks
Image gen code..
public class getimage : IHttpHandler {
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void ProcessRequest (HttpContext context) {
try
{
string uniqueid = "";
if(context.Request.QueryString["id"]) uniqueid = context.Request.QueryString["id"].ToString();
string dir = "~/imagecache/";
string image_target_path = dir + "image-file-" + uniqueid + ".png";
byte[] data = null;
context.Response.ContentType = "image/png";
if (!System.IO.File.Exists(context.Server.MapPath(image_target_path)))
{
if (context.Request.QueryString["id"] != null)
{
// get image data from the database
data = ImageHelper.getDatabaseImageDataByID(Convert.ToInt32(uniqueid));
using (System.Drawing.Image img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(data)))
{
// save image to disk in the virtual dir
img.Save(context.Server.MapPath(image_target_path));
}
}
else
{
// set a sample image if no id is set
image_target_path = "~/images/noimage.png";
}
}
// redirect request to image file
context.Response.Redirect(image_target_path, false);
}
catch (Exception ex)
{
log.Error(ex.Message, ex);
}
}
public bool IsReusable {
get {
return false;
}
}
}