net/http set content-type for images

I need to pull an image from a URL (I have permission) that is a .jpg.
I know I need to set the content-type to 'image/jpeg', but not sure
where to do that at.

result = Net::HTTP.get_response(URI.parse('http://
link_to_image.jpg') )

result.body => gives me encoded junk.

Looking for help on how to set the content-type so I can display the
image.

Thanks in advance.

I need to pull an image from a URL (I have permission) that is a .jpg.

result = Net::HTTP.get_response(URI.parse('http://
link_to_image.jpg') )

result.body => gives me encoded junk.

No, it gives you what you asked for: a JPEG-format IO stream.

Are you saving it, or passing it to some other process, or what?

so I can display the image.

Or in other words, "display" it how?

I am asking how to turn the JPEG IO stream into an image I can pass on
and display in a view.

So I have

def index
result = Net::HTTP.get_response(URI.parse('http://
link_to_image.jpg') )
...
@image = ??

end

index.html.erb
@image = pretty picture

Sorry, I originally thought this was to the ruby list...

Really? Do you really think there isn't a reason why I am not just
using an image_tag? Really?

The image is protected and I have been given access to pull it from my
web server to use in my app.

Looking for help in answering my original post please. Thanks.

Really? Do you really think there isn't a reason why I am not just
using an image_tag? Really?

Seems like a legitimate question to me.

The image is protected and I have been given access to pull it from my
web server to use in my app.

Looking for help in answering my original post please. Thanks.

All an image is is a stream of bytes, which you have already got.
Furthermore the image is fetched by a separate request. If you really
need to go down this route you should probably craft the <img> tag to
point at a particular controller/action in your app and from that
action make your http request and return the bytes you get. You might
also want to cache the image on your server.

Or perhaps some rewrite rules to proxy those requests to the origin
server might make more sense

Fred

Thanks that did it. I am caching the image - though since it's a
webcam image that needs refreshed to stay current the cache is short
lived.

def image
@result = Net::HTTP.get_response(URI.parse('http://
link_to_image.jpg') ).body
end

index.html
<img src="webcam/image'>

image.html.erb
@result