pohkong
asked on
<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 .Connectio n")
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?
<IMG SRC="GetImage.asp">
The GetImage.asp script may look like this:
<%
Set db = Server.CreateObject("ADODB
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?
ASKER
Dear xabi,
i have try your way, but still the same.
i have try your way, but still the same.
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
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
ASKER
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.as p, 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.
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.as
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.
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
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
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%>">
if just the name of the image you can use
<img src="images/<%=BigBlog%>">
ASKER
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.
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.
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
dear clockwatcher,
do you know that the oleheadersize for jpeg or gif.
do you know that the oleheadersize for jpeg or gif.
dear clockwatcher,
do you know that the oleheadersize for jpeg or gif.
do you know that the oleheadersize for jpeg or gif.
dear clockwatcher,
do you know that the oleheadersize for jpeg or gif.
do you know that the oleheadersize for jpeg or gif.
ASKER
dear clockwatcher,
do you know that the ole header size for jpeg or gif.
do you know that the ole header size for jpeg or gif.
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(strFullP ath))
filenum = FreeFile()
Open strFullPath For Binary As filenum
Get filenum, , fileBytes
Close filenum
Set rs = CurrentDb.OpenRecordset("t blPictures ", 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.OL EDB.3.51;D ata 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(OLE HEADERSIZE )
imageBytes = rs("picture").GetChunk(nFi eldSize - 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
%>
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(strFullP
filenum = FreeFile()
Open strFullPath For Binary As filenum
Get filenum, , fileBytes
Close filenum
Set rs = CurrentDb.OpenRecordset("t
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.OL
set rs = server.createobject("ADODB
rs.open "select * from tblPictures where pictureid=" & request.querystring("id"),
if not rs.eof then
select case rs("type")
case "olebmp":
ctype = "image/bmp"
nFieldSize = rs("picture").ActualSize
oleHeader = rs("picture").GetChunk(OLE
imageBytes = rs("picture").GetChunk(nFi
case else:
ctype = "image/" & rs("type")
imageBytes = rs("picture")
end select
end if
rs.close
set rs = nothing
response.contenttype = ctype
Response.BinaryWrite imageBytes
%>
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