Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-01-2013, 11:48 AM   PM User | #1
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,432
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
binary right an image

How can I take a url and binary wite the image (so that it can be accessed in an img src with url of asp page)?
esthera is offline   Reply With Quote
Old 02-01-2013, 09:40 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Are you asking how you can do something like:
<img src="getImage.asp?id=73" />
???

If not, I don't understand the question at all.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 02-02-2013, 04:33 PM   PM User | #3
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,432
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
yes bit in getimage.asp if i put response.write and link --it doesn't work

someone suggested I need to write it out as binary data?
esthera is offline   Reply With Quote
Old 02-03-2013, 03:37 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Yes, it's not hard.

Assuming that you are using <img src="getImage.asp?id=73" /> you would need to do
Code:
<%
' make sure that the < in the above line is the FIRST CHARACTER in the ASP page!!!
'
' what image was requested?
imageid = CLNG( Request("id") )

... here you need to go find the image to match the imageid ...
... we will assume that you find some FILENAME, here called fname:
fname = ... you supply this code ...

' Set the content type to the specific type that you are sending.
' Find the extension of the fname, thus:
period = InStrRev(fname,".")
If period = 0 Then Response.End
fext = Mid(fname,period+1)

' Then tell the browse what the type is:
Response.ContentType = "image/" & fext

Set strm = Server.CreateObject("ADODB.Stream")
strm.Open
strm.Type = 1 ' binary stream

' assuming fname is *RELATIVE* to the current directory:
strm.LoadFromFile Server.MapPath(fname)
' (omit the Server.MapPath if fname is already a full Windows path!)

Response.BinaryWrite strm.Read ' write the entire image out to the browser

strm.Close
Set strm = Nothing
Response.End ' important!
%>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
esthera (02-03-2013)
Old 02-03-2013, 04:38 AM   PM User | #5
esthera
Senior Coder

 
Join Date: May 2004
Posts: 1,432
Thanks: 14
Thanked 0 Times in 0 Posts
esthera can only hope to improve
that worked --thanks
esthera is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:52 AM.


Advertisement
Log in to turn off these ads.