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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sun, Jun 6, 2010 at 5:40 PM, Kim <kim.griggs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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? -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Jun 6, 6:37 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Jun 6, 2010 at 5:40 PM, Kim <kim.gri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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? > > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassan-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sorry, I originally thought this was to the ruby list... On Sun, Jun 6, 2010 at 8:17 PM, Kim <kim.griggs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am asking how to turn the JPEG IO stream into an image I can pass on > and display in a view.> def index > result = Net::HTTP.get_response(URI.parse(''http:// > link_to_image.jpg'') )> index.html.erb > @image = pretty pictureUh, why not just use an image_tag with the URL of the image?? Why are you even using Net::HTTP ? -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. On Jun 6, 8:52 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Sorry, I originally thought this was to the ruby list... > > On Sun, Jun 6, 2010 at 8:17 PM, Kim <kim.gri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I am asking how to turn the JPEG IO stream into an image I can pass on > > and display in a view. > > def index > > result = Net::HTTP.get_response(URI.parse(''http:// > > link_to_image.jpg'') ) > > index.html.erb > > @image = pretty picture > > Uh, why not just use an image_tag with the URL of the image?? Why > are you even using Net::HTTP ? > > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassan-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jun 7, 7:05 am, Kim <kim.gri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Jun 7, 1:07 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jun 7, 7:05 am, Kim <kim.gri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.