# Save image in local machine

**URL:** <https://www.ruby-forum.com/t/save-image-in-local-machine/165553>\
**Category:** Ruby\
**Created:** [April 15, 2009, 7:34am UTC](https://www.ruby-forum.com/t/save-image-in-local-machine/165553 "2009-04-15T07:34:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jazzezravi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71e660/32.png) [@jazzezravi](https://www.ruby-forum.com/u/jazzezravi)\
**Post date:** [April 15, 2009, 7:34am UTC](https://www.ruby-forum.com/t/save-image-in-local-machine/165553/1 "2009-04-15T07:34:18Z")

</div>

Hi All,

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

> **[Gmail](https://accounts.google.com/v3/signin/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2Fu%2F0%2F&emr=1&followup=https%3A%2F%2Fmail.google.com%2Fmail%2Fu%2F0%2F&ifkv=AeDOFXg4cCGuXqLfMVVZN09ZdkG41DWcHdEqP0iaAe9IGnNMDdaWQ5JVA9ALHoI4eldvsMXTy0Df&osid=1&passive=1209600&service=mail&flowName=GlifWebSignIn&flowEntry=ServiceLogin&dsh=S-150364714%3A1690698030157895)**
>
> Gmail is email that’s intuitive, efficient, and useful. 15 GB of storage, less spam, and mobile access.

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

Thanks in advance,  
P.Raveendran

> **[Raveendran](https://raveendran.wordpress.com)**
>
> Nothing is impossible...

---

<div class="post-metadata">

**Author:** ![jazzezravi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71e660/32.png) [@jazzezravi](https://www.ruby-forum.com/u/jazzezravi)\
**Post date:** [April 15, 2009, 8:12am UTC](https://www.ruby-forum.com/t/save-image-in-local-machine/165553/2 "2009-04-15T08:12:47Z")

</div>

Hi,

2009/4/15 Raveendran P. [removed\_email\_address@domain.invalid](mailto: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](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.

---

<div class="post-metadata">

**Author:** ![jazzezravi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71e660/32.png) [@jazzezravi](https://www.ruby-forum.com/u/jazzezravi)\
**Post date:** [April 15, 2009, 8:28am UTC](https://www.ruby-forum.com/t/save-image-in-local-machine/165553/3 "2009-04-15T08:28:35Z")

</div>

Heesob P. wrote:

> Hi,
> 
> 2009/4/15 Raveendran P. [removed\_email\_address@domain.invalid](mailto: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](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

> **[Raveendran](https://raveendran.wordpress.com)**
>
> Nothing is impossible...

---

<div class="post-metadata">

**Author:** ![jazzezravi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71e660/32.png) [@jazzezravi](https://www.ruby-forum.com/u/jazzezravi)\
**Post date:** [April 15, 2009, 8:39am UTC](https://www.ruby-forum.com/t/save-image-in-local-machine/165553/4 "2009-04-15T08:39:08Z")

</div>

Hi park,

I got the solution to change the line like this

File.open(“c:\TML\1.gif”,‘wb’)

Thanks.  
P.Raveendran

> **[Raveendran](https://raveendran.wordpress.com)**
>
> Nothing is impossible...
