|
 |
asp_databases thread: Newbie question on displaying a JPEG in a blob MySQL field.
Message #1 by Edward Cox <ecox@b...> on Wed, 20 Feb 2002 23:34:37 +1100
|
|
Hello,
Please bear with me if I don't describe this too well - I need some
assistance.
I have a MySQL database with a table with a BLOB field that I use to contain
a JPEG image (little endian - if that matters..).
What I need to do now, once I grab a row/record is to display that JPEG
field via my ASP page. And that's where I've come unstuck.
-- code snippet so far --
Dim varContactID
Dim varFirstName
Dim varLastName
.. Snip ..
Dim varPhotoPath
Dim varCategoryID
Dim varPhoto
varSQLCriteria = "SELECT gallery.id, gallery.g_company, gallery.g_lastname,
gallery.g_firstname," & _
" gallery.g_title, gallery.g_position, gallery.g_street, gallery.g_suburb,
gallery.g_state, gallery.g_postcode, " &_
" gallery.g_email, gallery.g_www, gallery.g_biography, gallery.g_quote,
gallery.g_country, gallery.g_phone, " &_
" gallery.g_fax, gallery.g_photopath, gallery.g_category, gallery.g_career,
gallery.g_photo " &_
" FROM gallery "
varFrmContactID = Request.QueryString("ContactID")
varSQLCriteria = varSQLCriteria & " WHERE gallery.id = " & varFrmContactID
Set objRecordSet = Server.CreateObject("ADODB.Recordset")
With objRecordSet
Set .ActiveConnection = GetDBConnection()
.Open(varSQLCriteria)
End With
%>
Then later..
--- --- ---
<%varContactID = objRecordSet("id")
varCompany = "" & objRecordSet("g_company")
varLastName = "" & objRecordSet("g_lastname")
.. Snip ..
varCareer = "" & objRecordSet("g_career")
varPhotoPath = "images/gallery/" & objRecordSet("g_photopath")
varPhoto = objRecordSet("g_photo")
%>
The problem, I guess, is that the field varPhoto contains binary data (the
JPEG) and now I need to display that as a JPEG.
Can someone offer advice to help me?
Thank you,
Ed Cox
PDQ Software
ecox@b...
Sydney, Australia
Message #2 by "Ken Schaefer" <ken@a...> on Thu, 21 Feb 2002 12:41:51 +1100
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: The problem, I guess, is that the field varPhoto contains binary data (the
: JPEG) and now I need to display that as a JPEG.
:
: Can someone offer advice to help me?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can't send back a webpage + jpeg as one file.
You need to send back the webpage, which contains a reference to the jpeg in
an
<img src="..."> tag
To send back the jpeg you just set the appropriate Response.ContentType
header, then Response.BinaryWrite the binary data:
For example of code:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q173308
Cheers
Ken
Message #3 by ashay@w... on Thu, 21 Feb 2002 06:28:32
|
|
hi,
u can use <img src="mypicture.asp">
then in my picture.asp use
<%
Response.ContentType = "image/jpg"
Dim Con'Ur Connection object
Set Rs=Serve.createObject("ADODB.Recordset")
sql="Select picture from mytable where id=" & id
Rs.open sql,Con
Response.BinaryWrite(Rs("picture"))
%>
hope this helps......
regards,
ashay
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> : The problem, I guess, is that the field varPhoto contains binary data
(the
> : JPEG) and now I need to display that as a JPEG.
> :
> : Can someone offer advice to help me?
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> You can't send back a webpage + jpeg as one file.
> You need to send back the webpage, which contains a reference to the
jpeg in
> an
> <img src="..."> tag
>
> To send back the jpeg you just set the appropriate Response.ContentType
> header, then Response.BinaryWrite the binary data:
>
> For example of code:
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;q173308
>
> Cheers
> Ken
>
|
|
 |