Link to home
Start Free TrialLog in
Avatar of dgwest
dgwest

asked on

Pulling GIF images from an Access Database

I want to create an employee database that has info like name, extension, email, etc and a picture (gif) of the the employee.  I know how to pull text from my Access database but I don't know how to pull images.  Does anyone know of any tutorials out there that could help?  Or maybe some past experiences?
Avatar of PBall
PBall

I think this topic has come up a lot of times before.

My suggestion, as many might have suggested before, is to keep the image outside of the database and store a pointer (filename) to the image files instead.
dgwest

Check out my previous question https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=10236282 

I asked exactly the same question a week or so back. Should resolve your problem.

As PBall stated above, don't try to get the imager from access but hold the images in your web in a folder called "photos" for want of a better example. then insert a column called photos in you data base and (If yor photo is called abc.gif) then enter abc in the record it relates to and have the asp page call the record write abc and then write .gif

I won't copy and paste another experts answer so check out the PAQ and all it'll cost you is 10 points.

Can't say fairer than that.

Regards

Nick
Avatar of Mark Franz
You can use three approaches to deliver the image from the database to the browser. The first way is to keep the image file on the hard drive, and store the file's name and path in the database. I don't recommend this approach, because putting the image file and its path in two different locations causes management problems. For example, if you change the filename, you must change the data entry in the database for its associated path. The second approach is to use the ASP Response object's BinaryWrite method. This method passes the image to the browser as an HTTP transaction with an HTTP header containing the IMAGE/GIF or IMAGE/JPEG type. Suppose you have a recordset named Rs that contains the image column Prod_pic in the Store database's Product table. This code demonstrates how to apply the ASP Response object's BinaryWrite method, where Cn is an instance of the ADO Connection object:


Response.Buffer = TRUE
Response.Clear
Response.ContentType = "image/gif"
Sql = "SELECT Prod_pic FROM" & _
      "Product WHERE Prod_id = 2"
Set Rs = Cn.Execute(Sql, , _ adCmdText)
Response.BinaryWrite Rs("Prod_pic")
Response.End

You must use the Response object's Clear method; otherwise users will see only ASCII in the browser, not the image. However, the Clear method erases any buffered HTML output. As a result, this piece of code displays only an image on the screen.

There's a better way to display images that allows you to have HTML together with the image. This method circumvents the management problems of image data, because it centralizes image data in the database. Use the Field object's GetChunk method in ADO to retrieve the BLOB's content. Then, save the BLOB's content to a disk file using the VB Put statement. You don't need to worry about what type of images (GIF or JPG) are stored in the database. After you create the image file, you can put its path as the SRC attribute in the IMG tag.

Mark
Aulrich,  Did you notice that the code snippet from your reference is exactly like my previous post?  Interesting...  I like the fact that everything is pretty much fully explained in detail though.

The key statement is the content type;

Response.ContentType = "image/gif"

THis is the key to posting the reference correctly,

Hope this helps.

Mark
Avatar of dgwest

ASKER

I've read that article in the past and I wasn't impressed with it.  I did get it working thanks to NickRackham's post though.  Sorry for asking a question that was previously asked and thanks for the help. Derek.
While Nick's solution is an OK one, it might create a headache later if the image directory grows to large proportions...  how will you know if an image should be deleted when an employee leaves the company.  It would be east to write a script that would delete every instance that is associated with a certain employee, including the image file.

Since you have already created a record for the file name, why not store the file itself instead of just the name?

My two cents.

Mark
Derek,

May I post as an answer?

Nick
Avatar of dgwest

ASKER

Yep
ASKER CERTIFIED SOLUTION
Avatar of NickRackham
NickRackham

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial