CGI returning binary data
[1/5] from: anton::lexicon::net at: 14-Sep-2002 20:30
Hello fellow rebolers,
I am looking for an example cgi
to return image data, eg. a gif image,
so it can be used like this:
<img src="generate-img.cgi">
Anton.
[2/5] from: gscottjones:mchsi at: 14-Sep-2002 7:08
From: "Anton"
> I am looking for an example cgi
> to return image data, eg. a gif image,
> so it can be used like this:
>
> <img src="generate-img.cgi">
Hi, Anton,
Borrowing from a thread a couple of weeks ago:
;;;;;jpeg.cgi in cgi-bin (or equivalent directory)
#!/path/to/rebol -cs
REBOL []
print "Content-type: image/jpeg^/"
set-modes system/ports/output [binary: true]
insert system/ports/output read/binary %//rebol/view/nyc.jpg
;;;;;;image.html file
<html>
<body>
<h1>image/jpeg</h1>
<center>
<img border="1"
src="http://localhost/cgi-bin/jpeg.cgi" alt="Streamed Image">
</center>
</body>
</html>
I know it is not gif, but same principle. Hope this helps.
--Scott Jones
[3/5] from: jjmmes:y:ahoo:es at: 14-Sep-2002 19:29
http://www.rebol.org/cgi/gif-number.r
--- "G. Scott Jones" <[gscottjones--mchsi--com]> escribió:
[4/5] from: anton:lexicon at: 16-Sep-2002 8:26
Thanks, Scott, Jose.
Doing:
set-modes system/ports/output [binary: true]
helped, and I was also missing the content-type
header line that I thought the server was inserting
into the port for me.
And, of course, using print, I inserted three
newline characters after the header instead of
two.
Sounds just like the usual cgi problems except
this time it's me with them!
Anton.
[5/5] from: chris:ross-gill at: 15-Sep-2002 20:15
Hi Anton,
> <img src="generate-img.cgi">
Content of %generate-img.cgi:
#!path/to/rebol --cgi
[
REBOL []
image-data: read/binary %image.png
print "content-type: image/png^/"
write-io system/ports/output image-data length? image-data
]
- Chris