Solved

View Image from Access DB

Posted on 2000-02-17
6
284 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with stored procedure 30 59
classic asp checkbox uncheck and check 2 58
Summernote and form validation 10 97
Error viewing ASP page 12 148
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

17 Experts available now in Live!

Get 1:1 Help Now