Solved

View Image from Access DB

Posted on 2000-02-17
6
283 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
  • 3
  • 2
6 Comments
 
LVL 28

Expert Comment

by:sybe
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:woosey
Comment Utility
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
Comment Utility
0
 

Author Comment

by:woosey
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
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 video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now