Forum: Ruby on Rails Download an Image using Net::HTTP

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
34791e1d8c4def65f9b93294638a7e04?d=identicon&s=25 Joerg Diekmann (joergd)
on 2006-01-22 12:57
Hi,

I need to download an image, and I've mucked about with Net::HTTP

resp = Net::HTTP.get_response('www.mydomain.com', '/test.jpg')
f = File.new("test.jpg","w")
f.write(response.body)

And various other combinations using HTTP.get etc. Anyway, I get an
image, but it looks very psychedelic. This is obviously not the correct
way. I also don't want to use Imagemagick for this.

Has anybody done this before?

Joerg
0fd334c46e284c02d4622a8ac429b236?d=identicon&s=25 Anthony Elizondo (Guest)
on 2006-01-22 17:12
(Received via mailing list)
On 1/22/06, Joerg Diekmann <joergd@pobox.com> wrote:
> way. I also don't want to use Imagemagick for this.
>
> Has anybody done this before?

Are you on Windows? If so, you need to use:

f = File.new("test.jpg","wb")

See http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/...
for a discussion of why, and
http://www.ruby-doc.org/core/classes/IO.html for the documentation of
this mode.

> Joerg

Anthony
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-01-22 22:30
(Received via mailing list)
On Jan 22, 2006, at 8:06 AM, Anthony Elizondo wrote:

>> image, but it looks very psychedelic. This is obviously not the
> for a discussion of why, and
> http://www.ruby-doc.org/core/classes/IO.html for the documentation of
> this mode.
>
>> Joerg
>
> Anthony



Also you are trying to write response.body into the file when you
should be using resp.body because resp is the var you used to set up
the Net::HTTP object

Cheers-
-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
ezra@yakima-herald.com
509-577-7732
34791e1d8c4def65f9b93294638a7e04?d=identicon&s=25 Joerg Diekmann (joergd)
on 2006-01-26 12:25
Ah - of course. Thank you.

> Are you on Windows? If so, you need to use:
>
> f = File.new("test.jpg","wb")
>
This topic is locked and can not be replied to.