Solved

View Image from Access DB

Posted on 2000-02-17
6
289 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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/…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

626 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