Forum: Ruby Save image in local machine

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.
Raveendran .. (Guest)
on 2009-04-15 09:34
Hi All,


I want to save this image in my local machine with ruby code

https://mail.google.com/mail/help/images/logo.gif

Note: I did with Watir gem. But I want to do it another simple way.


Thanks in advance,
P.Raveendran
http://raveendran.wordpress.com
Heesob P. (Guest)
on 2009-04-15 10:12
(Received via mailing list)
Hi,

2009/4/15 Raveendran P. <removed_email_address@domain.invalid>:
> Hi All,
>
>
> I want to save this image in my local machine with ruby code
>
> https://mail.google.com/mail/help/images/logo.gif
>
> Note: I did with Watir gem. But I want to do it another simple way.
>

    require 'net/https'
    require 'uri'

    url = 'https://mail.google.com/mail/help/images/logo.gif'
    uri = URI.parse(url)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true if uri.scheme == "https"
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    http.start {
      http.request_get(uri.path) {|res|
        File.open(File.basename(uri.path),'wb') { |f|
      f.write(res.body)
  }
      }
    }


Regards,

Park H.
Raveendran .. (Guest)
on 2009-04-15 10:28
Heesob P. wrote:
> Hi,
>
> 2009/4/15 Raveendran P. <removed_email_address@domain.invalid>:
>> Hi All,
>>
>>
>> I want to save this image in my local machine with ruby code
>>
>> https://mail.google.com/mail/help/images/logo.gif
>>
>> Note: I did with Watir gem. But I want to do it another simple way.
>>
>
>     require 'net/https'
>     require 'uri'
>
>     url = 'https://mail.google.com/mail/help/images/logo.gif'
>     uri = URI.parse(url)
>     http = Net::HTTP.new(uri.host, uri.port)
>     http.use_ssl = true if uri.scheme == "https"
>     http.verify_mode = OpenSSL::SSL::VERIFY_NONE
>     http.start {
>       http.request_get(uri.path) {|res|
>         File.open(File.basename(uri.path),'wb') { |f|
>       f.write(res.body)
>   }
>       }
>     }
>
>
> Regards,
>
> Park H.

Hi Park,

Thanks for your code and also I need to save the image in Given path
like c:\raveendran\

Where I can add this path in above program ?

Thanks
P.Raveendran
http://raveendran.wordpress.com
Raveendran .. (Guest)
on 2009-04-15 10:39
Hi park,

I got the solution to change the line like this

File.open("c:\\TML\\1.gif",'wb')


Thanks.
P.Raveendran
http://raveendran.wordpress.com
This topic is locked and can not be replied to.