views:

48

answers:

1

Hi,

I'm using ASP.net/C# and trying to build an image gallery. My images are stored as byte data in the database and im using an axd file like so, getDocument.axd?attachmentID= X, to set an Image object which is then added to the aspx page on page load.

In IE most of the images are rendered to the page however certain images arn't rendered i get the default red x image. Interestingly when i view the properties of the image it does not have a file type. The files that im retrieving are all jpg's.

I hope someone can help because this is a real head scratcher :)

I must note that this issue does not occur in firefox/chrome and all images render correctly.

void IHttpHandler.ProcessRequest(HttpContext context)
    {

        if (context.Request.QueryString["attid"] != null)
        {
            int attid = int.Parse(context.Request.QueryString["attid"]);

            context.Response.Clear();
            context.Response.AddHeader("Content-Length", att.AttachmentData.Length.ToString());
            context.Response.ContentType = att.MimeType.MimeHeader;
            //context.Response.CacheControl = "no-cache";
            context.Response.AddHeader("Content-Disposition", "attachment; filename=" + att.FileName.Replace(" ", "_") + "." + att.MimeType.FileExtension + ";");
            context.Response.OutputStream.Write(att.AttachmentData, 0, att.AttachmentData.Length);
            context.Response.End();

            return;
        }
    }

In order to call this method i get a List of ids from the db and pull back the corresponding images doing the following;

            foreach (int i in lstImages)
            {
                Image tempImage = new Image();
                Panel pnl = new Panel();
                tempImage.ImageUrl = "getDocument.axd?attid=" + i;
                tempImage.Attributes.Add("onclick", "javascript:populateEditor(" + i + ");");
                tempImage.Height = 100;
                tempImage.Width = 100;
                pnl.Controls.Add(tempImage);
                divImages.Controls.Add(tempImage);
            }

* EDIT * A colleague of mine noticed that some of my images had strange header information contained in the image file. We suspect that this might be from photoshop saving files as all files which have not been created from a specific person seem to display fine.

A: 

Having done this myself I've never encountered this problem. Does this occur for the same image(s) or is it semi-random?

Check the jpegs are viewable in IE normally (i.e. as a source file not through your handler), check the HTTP traffic with fiddler, and check the bytestream going out looks good.

annakata
The images that are causing issues are not viewable if i just hard code the <img src="getDocument.axd?id=bla> However you can download and open them
Garbit