<IMG SRC="GetImage.asp"> ?

i try to get image from database with a  html like below:
<IMG SRC="GetImage.asp">

The GetImage.asp script may look like this:

<%
Set db = Server.CreateObject("ADODB.Connection")
db.Open "data"
Set rs =db.Execute("SELECT BigBlob FROM Blobs where id = 'ABC' )
Response.ContentType = "image/jpeg" '(or "image/gif")
Response.BinaryWrite rs("BigBlob")
%>

the question is i can't get the image in the html page. why? is that any wrong my method or coding?

can we display *.ico image on a button?
pohkongAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

xabiCommented:
I think you have a bad query, cause you forgot to close the double quotes of the query:

Try this query:

Set rs =db.Execute("SELECT BigBlob FROM Blobs where id = 'ABC'")

If don't work change your code into mine, this way:

<%
response.Expires = 0
response.Buffer  = True
response.Clear
response.contentType = "image/gif"

..
..
Read database
..
..
response.BinaryWrite rs("BigBlob")
rs.Close
Set rs = Nothing
response.End
%>


xabi
0
pohkongAuthor Commented:
Dear xabi,

i have try your way, but still the same.
0
xabiCommented:
hmmm this method works for me. Don't you get any error?

Try this:

comment the contentType line and maketry to open this page not as an Image but as an html page. So you can see the errors.
To do this just type in you browser:

http://www.yoursite.com/Getimage.asp

This way will see what's happening.

xabi
0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

pohkongAuthor Commented:
dear xabi,

i have try your way, i got the following error message.

ADODB.Fields error '800a0cc1'

ADO could not find the object in the collection corresponding to the name or ordinal reference requested by the application.

/Project1/uploadscript4.asp, line 31

i am using the ms access to store the image in database as an ole object. do i need to do any setting on it.
0
xabiCommented:
Why don't you try your query in a query analizer or in your access? I think your query doesn't return you any row, so you don't have access to the field ("BigBlob"). It the query is right and you have the data and still don't work try this:

response.BinaryWrite rs.fields("BigBlob")

You can also continue debugging your script this way:

1.- continue with the content type line commented.
2.- add this t your code:

if rs.eof then
  response.write("No data")
else
  response.write("I have some data")
end if

instead of

response.BinaryWrite rs("BigBlob")

xabi
0
CritCommented:
are you keeping the whole image tag in the database or just the name?

if just the name of the image you can use

<img src="images/<%=BigBlog%>">
0
pohkongAuthor Commented:
dear xabi,
i have try sql statement in access, i got data from the sql statement. and i also run the script and i got the out "I have some data"
but the problem is i still can't get the image in the html page.
0
pohkongAuthor Commented:
dear crit,
i am using the ms access to store the image in database as an ole object. i think it is the whole image tag, isn't it? do i need to do any setting in order to get the image from the database?
0
clockwatcherCommented:
Access stores an image as an OLE object, which contains extra information regarding the object's type.  Unlike SQL server, it's not just a BLOB of the image.  You have to strip out the extra OLE information.

See the following article.

  http://www.asptoday.com/articles/19990719.htm

Basically, it boils down to stripping out the first 78 bytes which contain the OLE header info, but you might want to read the article anyway-- as you can also check the header to determine the image-type (jpeg, gif, bmp).

<%
    Const OLEHEADERSIZE = 78
    nFieldSize = rs("photo").ActualSize
    oleHeader = rs("photo").GetChunk(OLEHEADERSIZE)
    imageBytes = rs("photo").GetChunk(nFieldSize - OLEHEADERSIZE)
    Response.BinaryWrite imageBytes
%>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mkngauCommented:
dear clockwatcher,

do you know that the oleheadersize for jpeg or gif.
0
mkngauCommented:
dear clockwatcher,

do you know that the oleheadersize for jpeg or gif.
0
mkngauCommented:
dear clockwatcher,

do you know that the oleheadersize for jpeg or gif.
0
pohkongAuthor Commented:
dear clockwatcher,

do you know that the ole header size for jpeg or gif.
0
clockwatcherCommented:
The actual object and raw data associated with it that gets stored in your Access database depends upon whatever object server you have registered to handle the particular file type you're inserting.  In my case (on the computer I'm currently working with), Corel Photopaint is registered to handle GIFs and JPGs, so when I embed a GIF or JPG into Access (using insert object), Corel takes over and stores it however it wants to see the data (a CPT file with additional OLE header information).  Basically, what I'm saying is that the raw data associated with your object isn't necessarily going to still be a gif or a jpg-- it's going to be decided by whatever server object controls the OLE document.

The easiest way to store images within an Access database is to store the raw data yourself, rather than store the image as an OLE object (with Insert Object).  For example, suppose you have the following fields:

TblPictures
  PictureID  Autonumber
  Type       Text(10)
  Picture    OLE

You can insert the raw data into your OLE field with the AppendChuck method.  So for example, the following Access function will store an image as a BLOB datatype within the Picture field.

Function addPicture(strFullPath)

    Dim rs As Recordset
    Dim fileBytes() As Byte
    Dim filenum As Integer
   
    ReDim fileBytes(FileLen(strFullPath))
   
    filenum = FreeFile()
   
    Open strFullPath For Binary As filenum
    Get filenum, , fileBytes
    Close filenum
   
    Set rs = CurrentDb.OpenRecordset("tblPictures", dbOpenTable, dbAppendOnly, dbOptimistic)
    rs.AddNew
    rs("type") = IIf(Right(strFullPath, 3) = "jpg", "jpeg", Right(strFullPath, 3))
    rs("picture") = fileBytes
    rs.Update
    rs.Close
   
    Set rs = Nothing
   
End Function


You lose the OLE aspect of the object-- you can't double-click it and start up the server application.  But, you've now stored the raw data into your field, so you can simply binary write it on your ASP page.  If you actually open up tblPictures and look at the data, you'll see that the description of picture says Large Binary Object not Corel Photopaint Image (or whatever you've got registered).

Anyway, I posted a sample that pulls the three images on the page from an Access database-- two are raw images (one gif, one jpg) the other is an OLE BMP image.  You can check it out at:

  http://experts-exchange.yahright.com/accesspicture/

A zip file containing the database, the asp page, and the html file is at:

  http://experts-exchange.yahright.com/accesspicture/accesspicture.zip

The following is the source for the getpicture.asp page which actually pulls the image from the database:

<%

  Const OLEHEADERSIZE = 78
 
  strconn = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & server.mappath(".") & "\picturedb.mdb"
  set rs = server.createobject("ADODB.Recordset")
  rs.open "select * from tblPictures where pictureid=" & request.querystring("id"), strconn
 
  if not rs.eof then
     
     select case rs("type")
        case "olebmp":  
 
            ctype = "image/bmp"
            nFieldSize = rs("picture").ActualSize
            oleHeader = rs("picture").GetChunk(OLEHEADERSIZE)
            imageBytes = rs("picture").GetChunk(nFieldSize - OLEHEADERSIZE)
       
       case else:  

            ctype = "image/" & rs("type")
            imageBytes = rs("picture")

     end select
  end if
 
  rs.close
  set rs = nothing

  response.contenttype = ctype
  Response.BinaryWrite imageBytes

%>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.