Newb CGI Question

M

Michael Buffington

So I thought I had CGI in Ruby figured out, but I'm stumped on the following:

I want use Ruby to dynamically serve an image. The image tag would
look like <img src="file.rb?id=200">, where 200 is the id for an
image.

So here's what I have (I'm trading embarrassment for guidance):

require "cgi"
cgi = CGI.new("html4")
cgi.out('image/png')
File.read('200.png')

Now, I'm pretty sure I'm not reading the file right, but what I seem
to be stuck on first is getting my MIME type right. When hitting the
CGI, I can't get Content-Type to come back as 'image/png'. It's always
'text/html'.

Any tips?
 
J

Joost Diepenmaat

So I thought I had CGI in Ruby figured out, but I'm stumped on the following:

I want use Ruby to dynamically serve an image. The image tag would
look like <img src="file.rb?id=200">, where 200 is the id for an
image.

So here's what I have (I'm trading embarrassment for guidance):

require "cgi"
cgi = CGI.new("html4")
cgi.out('image/png')
File.read('200.png')

Shouldn't that be

cgi.header("image/png") {
File.read('200.png');
}

Or something similar?

J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,468
Latest member
Fannie44U3

Latest Threads

Top