?
Solved

View Image from Access DB

Posted on 2000-02-17
6
Medium Priority
?
290 Views
Last Modified: 2012-06-27
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(OLEHEADERSIZE)
            'imageBytes = cn("Data").GetChunk(nFieldSize - OLEHEADERSIZE)
 ' end if
     


      Response.ContentType = "image/jpeg"
      Response.BinaryWrite cn("Data")
      cn.close
      set cn = nothing
0
Comment
Question by:woosey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 2533865
If you have a valid connection named Conn, then the following code is ok:

<%
Response.ContentType = "image/GIF"

Set RSImage = Server.CreateObject("ADODB.Recordset")
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

0
 

Author Comment

by:woosey
ID: 2533900
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...
0
 
LVL 28

Accepted Solution

by:
sybe earned 210 total points
ID: 2533920
Strange, because it is the code I am using and it works fine...

Do you get errors ??
Do you get a corrupt image ??
What is the problem ??

It helps in devugging if you disable the Response.ContentType line. Then you will see error messages displayed in your browsers.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:woosey
ID: 2533940
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???
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 2534027
0
 

Author Comment

by:woosey
ID: 2541364
I tried it at home on my PWS and it works there so there is something wrong with the configuration on this end.......
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question