hi,
I am using the fileuplaod control to upload the images. For this I used to stored it in the cache
for 2 hours in byte format and show this image using the HttpContext in the .ashx file. For some Reason it
is sometime saving in the cache and sometime not. I am using asp.net 2.0 and C# language.
My code For Saving :
//Name of the Image
string strGuid = Guid.NewGuid().ToString();
byte[] byteImage = new byte[ImageUpload.PostedFile.ContentLength];
//file upload control ID "ImageUpload" and read it and save it in cache.
ImageUpload.PostedFile.InputStream.Read(byteImage, 0, byteImage.Length);
//Saving Byte in the cache
Cache.Add(strGuid, byteImage, null, DateTime.Now.AddDays(2), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
//Saving Image Format in cache
Cache.Add(string.Format("{0}_Type", strGuid), strContentType, null, DateTime.Now.AddDays(2), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
UserImage.ImageUrl = string.Format("~/UserControl/ImageHander.ashx?imgId={0}", strGuid);
Code For Rendering Image using .ashx file:
public void ProcessRequest (HttpContext context)
{
string strImageGuid = context.Request.QueryString["imgId"].ToString();
string strContentTypeID = string.Format("{0}_Type", context.Request.QueryString["imgId"].ToString());
byte[] byteImage =(byte []) context.Cache[strImageGuid];
string strContentType = (string)context.Cache[strContentTypeID];
context.Response.ContentType = strContentType;
context.Response.OutputStream.Write(byteImage, 0, byteImage.Length);
}
Is there any Problem In saving the byte image in cache Or any other better way of doing this?
Thanks! sanjay pal