Solved

View Image from Access DB

Posted on 2000-02-17
6
288 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 70 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

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

734 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