February 25th, 2003, 09:50 AM
using jpegs in Access
I'm having difficulty displaying an jpeg (or gif) on a website, getting it from a table in Access.
In my HTML i'm setting the image tag to retrieve from the 'pic' field in my database, have no problem with any connections, I'm retrieving text on the same page fine. The 'pic' field is an OLE object data type. When I select the jpeg(or gif) I want in an entry, it calls it a "Package".
I've tried a couple of books and all the help files, but can't find anything about it all. Surely it's pretty simple when you're creating dynamic page sites to retrieve images as well as text in Access??
February 25th, 2003, 11:34 PM
I ran into this problem before.
I will try to make this as simple and understandable as I can.
If there is an easier way anyone knows, please let all of us know.
When I had to do it I used ASP. so I will keep going as if it is going to be developed in asp.
A regular asp page that has html tags on is of content type "text/html" ... Response.ContentType
When you retrieve an image from the database , you are actually recieving the encoded binary file. A regular response.write(recordset.Fields("ImageField")), will not do it.
To write the image for the browser to read the content type should be set to "image/jpeg" or "image/gif"
Now you cannot switch from content type text to content type image on the same page.
Create a small asp page: Lets call it imageViewer.asp
Set rs = Server.CreateObject("ADODB.RecordSet")
ID = Trim ( Request("ID") & "")
Check on ID is valid ..... ID is the ID of the record that will have the image field.
Set rs = Database.Execute("SELECT * FROM tbl_Images ID = " & ID )
If NOT (rs.EOF AND rs.BOF) Then
Response.ContentType = "image/jpeg"
Response.BinaryWrite rs("Image Field Name")
Set rs = Nothing
Now from your regular asp page
the imag tag will look something like this
<IMG src = "images/ImageViewer.asp?ID=192837">
Another problem I have faced and this cost me alot of time.
"The binary code ACCESS will translate the image to" is different if the OLE object was imported "from inside ACCESS" than if it was "uploaded to the database using a webpage".
This only worked for me when the images where uploaded using an asp page.
I hope this is of any help, and please if you have any questions, just ask.
Last edited by yassoor; February 26th, 2003 at 12:02 AM.