# Grab Image From Web Server

**URL:** <https://www.ruby-forum.com/t/grab-image-from-web-server/51026>\
**Category:** Ruby\
**Created:** [November 29, 2005, 11:42pm UTC](https://www.ruby-forum.com/t/grab-image-from-web-server/51026 "2005-11-29T23:42:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/cdc98d/32.png) [@lists](https://www.ruby-forum.com/u/lists)\
**Post date:** [November 29, 2005, 11:42pm UTC](https://www.ruby-forum.com/t/grab-image-from-web-server/51026/1 "2005-11-29T23:42:53Z")

</div>

Hi,

I am still fairly new to Ruby.

Given the URL of an image, I would like to craft some code that grabs  
the  
image from the remote Web server and puts it in a file on the local  
machine.

Can anyone give me some tips on doing that?

Thanks,  
Hunter

---

<div class="post-metadata">

**Author:** ![lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/cdc98d/32.png) [@lists](https://www.ruby-forum.com/u/lists)\
**Post date:** [November 29, 2005, 11:49pm UTC](https://www.ruby-forum.com/t/grab-image-from-web-server/51026/2 "2005-11-29T23:49:12Z")

</div>

lists wrote:

> Hi,
> 
> I am still fairly new to Ruby.
> 
> Given the URL of an image, I would like to craft some code that grabs  
> the  
> image from the remote Web server and puts it in a file on the local  
> machine.
> 
> Can anyone give me some tips on doing that?
> 
> Thanks,  
> Hunter

requre ‘open-uri’  
open(“output\_filename.jpg”, “w”) { |outfile|  
outfile.write open(“http://image\_url.jpg”) { |inf|  
ifile.read  
}  
}

---

<div class="post-metadata">

**Author:** ![lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/cdc98d/32.png) [@lists](https://www.ruby-forum.com/u/lists)\
**Post date:** [November 29, 2005, 11:50pm UTC](https://www.ruby-forum.com/t/grab-image-from-web-server/51026/3 "2005-11-29T23:50:18Z")

</div>

jimweirich wrote:

> requre ‘open-uri’  
> open(“output\_filename.jpg”, “w”) { |outfile|  
> outfile.write open(“http://image\_url.jpg”) { |inf|  
> ifile.read  
> }  
> }  
> Oops … naming problem with inf and ifile … both should be infile.

Sorry  
– Jim W.

---

<div class="post-metadata">

**Author:** ![lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/cdc98d/32.png) [@lists](https://www.ruby-forum.com/u/lists)\
**Post date:** [November 30, 2005, 12:15am UTC](https://www.ruby-forum.com/t/grab-image-from-web-server/51026/4 "2005-11-30T00:15:12Z")

</div>

Thanks.

This is working like a charm!

---

<div class="post-metadata">

**Author:** ![lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/cdc98d/32.png) [@lists](https://www.ruby-forum.com/u/lists)\
**Post date:** [November 30, 2005, 12:19am UTC](https://www.ruby-forum.com/t/grab-image-from-web-server/51026/5 "2005-11-30T00:19:14Z")

</div>

Jim W. wrote:

> jimweirich wrote:
> 
> > requre ‘open-uri’  
> > open(“output\_filename.jpg”, “w”) { |outfile|

on Windows, make this “wb” for binary data.

James

–

[http://www.ruby-doc.org](http://www.ruby-doc.org) - Ruby Help & Documentation  
[Ruby Code & Style](http://www.artima.com/rubycs/) - Ruby Code & Style: Writers wanted  
[http://www.rubystuff.com](http://www.rubystuff.com) - The Ruby Store for Ruby Stuff  
[http://www.jamesbritt.com](http://www.jamesbritt.com) - Playing with Better Toys  
[http://www.30secondrule.com](http://www.30secondrule.com) - Building Better Tools

---

<div class="post-metadata">

**Author:** ![lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/cdc98d/32.png) [@lists](https://www.ruby-forum.com/u/lists)\
**Post date:** [April 20, 2009, 11:56am UTC](https://www.ruby-forum.com/t/grab-image-from-web-server/51026/6 "2009-04-20T11:56:02Z")

</div>

lists wrote:

> Hi,
> 
> I am still fairly new to Ruby.
> 
> Given the URL of an image, I would like to craft some code that grabs  
> the  
> image from the remote Web server and puts it in a file on the local  
> machine.
> 
> Can anyone give me some tips on doing that?
> 
> Thanks,  
> Hunter

Hi All,

Get all images from given URL

Desktop Application from jazzez

Kindly go through below link and download the EXE file.

> **[jazzez-image-v2.exe | Powered by Box](https://app.box.com/s/m5vxqpr3r1)**
>
> Get all images from the given URL

Install in Windows machine and enjoy with impressed images

Regards,  
P.Raveendran

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

---

<div class="post-metadata">

**Author:** ![lists](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/cdc98d/32.png) [@lists](https://www.ruby-forum.com/u/lists)\
**Post date:** [April 20, 2009, 3:48pm UTC](https://www.ruby-forum.com/t/grab-image-from-web-server/51026/7 "2009-04-20T15:48:47Z")

</div>

Could it be at all possible that a class has just been set an exercise  
of downloading an image from a webserver, and the class notes also  
pointed to the existence of the ruby-talk mailing list? 🙂
