woosey
asked on
View Image from Access DB
I'm trying to view an image from an access database that is stored as "long binary data"(My code with commeneted out attempts is below). I would prefer not to use a component and not to store the picture on the server seperately. Think it's something to do with the header but it just wont view anyway I try....
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear
' Const OLEHEADERSIZE = 78
dim cn
Set cn = Server.CreateObject("ADODB .Recordset ")
cn.Open "select * from News where ID=84", "DSN=news"
'if not cn.eof then
'nFieldSize = cn("Data").ActualSize
'oleHeader = cn("Data").GetChunk(OLEHEA DERSIZE)
'imageBytes = cn("Data").GetChunk(nField Size - OLEHEADERSIZE)
' end if
Response.ContentType = "image/jpeg"
Response.BinaryWrite cn("Data")
cn.close
set cn = nothing
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear
' Const OLEHEADERSIZE = 78
dim cn
Set cn = Server.CreateObject("ADODB
cn.Open "select * from News where ID=84", "DSN=news"
'if not cn.eof then
'nFieldSize = cn("Data").ActualSize
'oleHeader = cn("Data").GetChunk(OLEHEA
'imageBytes = cn("Data").GetChunk(nField
' end if
Response.ContentType = "image/jpeg"
Response.BinaryWrite cn("Data")
cn.close
set cn = nothing
ASKER
The data (image) is a jpeg file that has been uploaded to the database using the appendchunk method which results in a field containing "long binary data". The uploading side of things is working fine...No, this technique doesn't work...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, I know it works - I've used that code for other files but somethings happening with my header and I need a reliable stripping routine - Me thinks. I took the contenttype line out and it is just looping and not returning anything(no broken image icon or error)....It does this with the contenttype line in or out???
ASKER
I tried it at home on my PWS and it works there so there is something wrong with the configuration on this end.......
<%
Response.ContentType = "image/GIF"
Set RSImage = Server.CreateObject("ADODB
strSQL = "SELECT banner_image FROM banner WHERE banner_id=" & Request("banner_id")
RSImage.Open strSQL, Conn, 1, 1
Response.Binarywrite RSImage("banner_image")
RSImage.Close
%>
The point is how you have stored the images. If you have used OLE to store the images in ACCESS, then you should be aware that ACCESS does not store the exact binary code, but converts the image to BMP (and also keeps the original binary code in the field). So the result is NOT an image that you can display.
If you want to store the exact binary code of an image in an ACCESS field, you have to write some VBA or use some other code that adds the binary code to the field.
If you use file-upload from the web, the SA-FileUp can do that, look at http://www.spotartisans.com