Serving Images Stored in DB RRS feed

  • Question

  • User110260569 posted
    Hi I have created a system that serves images from a DB. The images are displayed ok in browsers but IE does does recognize the contenttype, and I suspect that this means that the images are not cached locally there is no file stored by the name in temporary Internet files. The code that is executed to respond with an image is : Response.Clear() Dim contentType As String = db.GetScalar("select extension from files where ID = " & Request("ID")) Response.ContentType = contentType If contentType.ToLower = "image/gif" Then Response.BinaryWrite(db.getbinaryData("select data from files where ID = " & Request ("ID"))) Else Dim _image As System.Drawing.Image = System.Drawing.Image.FromStream(New System.IO.MemoryStream(db.getbinaryData("select thumbdata from files where ID = " & Request("ID")))) _image.Save(Response.OutputStream, _image.RawFormat) _image.Dispose() End If I think the problem is a header field that is missing since IE does not recognize contenttype and size. Any ideas ? regards Lars Kohsel
    Thursday, November 11, 2004 9:49 AM

All replies

  • User-1372641848 posted
    you have to use correct content type. Response.ContentType = "image/gif"; And if you are using aspx file to serve image use Response.Clear and Response.End as shown below. Response.Clear() Response.ContentType = "image/gif" Response.BinaryWrite...... Response.End()
    Thursday, November 11, 2004 9:01 PM
  • User110260569 posted
    The contenttype is fetched from the posted file so its the same as the original, hence image/pjpeg or image/gif I have tried to include a Response.end() in the code, but IE still does not cache the file in temporary Internetfiles. The funny thing is that I have an ASP page that does approx. the same thing, returns an image through a response.binarywrite and IE caches these files without any problems in the temporary Internet files Does anyone know what headers should be available for local caching ? regards Lars Kohsel
    Friday, November 12, 2004 9:36 AM
  • User-1372641848 posted
    Sorry i misread your question.. Try with following headers. 1)Expires 2)Cache-Control 3)Last-Modified 4)ExpiresAbsolut
    Friday, November 12, 2004 11:26 AM