# Reading files from the internet into RMagick

**URL:** <https://www.ruby-forum.com/t/reading-files-from-the-internet-into-rmagick/69597>\
**Category:** Ruby\
**Created:** [September 22, 2006, 5:01am UTC](https://www.ruby-forum.com/t/reading-files-from-the-internet-into-rmagick/69597 "2006-09-22T05:01:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Szymon\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e480ec/32.png) [@Szymon\_R](https://www.ruby-forum.com/u/Szymon_R)\
**Post date:** [September 22, 2006, 5:01am UTC](https://www.ruby-forum.com/t/reading-files-from-the-internet-into-rmagick/69597/1 "2006-09-22T05:01:57Z")

</div>

I am not sure how to go about doing this. I would like to get a file  
given an URL. The I would like to mess around with that file, but I am  
having a hard time actually initializing the Magick::Image object.

I read the image using open-uri like so:  
require ‘rmagick’  
require ‘open-uri’  
include Magick

open(url) do |f|  
image = from\_blob(f.read)  
end

However, it turns out that f is of type “Tempfile” and calling read  
returns “” and read(int) returns nil. So I don’t know where to go from  
here. How can this be done?

Thanks,  
-Szymon

---

<div class="post-metadata">

**Author:** ![Szymon\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e480ec/32.png) [@Szymon\_R](https://www.ruby-forum.com/u/Szymon_R)\
**Post date:** [September 22, 2006, 5:26am UTC](https://www.ruby-forum.com/t/reading-files-from-the-internet-into-rmagick/69597/2 "2006-09-22T05:26:18Z")

</div>

On 9/21/06, Szymon R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> image = from\_blob(f.read)  
> end
> 
> However, it turns out that f is of type “Tempfile” and calling read  
> returns “” and read(int) returns nil. So I don’t know where to go from  
> here. How can this be done?

Does this work?  
open(url, ‘rb’) do |f|  
image = from\_blob(f.read)  
end

---

<div class="post-metadata">

**Author:** ![Szymon\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e480ec/32.png) [@Szymon\_R](https://www.ruby-forum.com/u/Szymon_R)\
**Post date:** [September 22, 2006, 4:11pm UTC](https://www.ruby-forum.com/t/reading-files-from-the-internet-into-rmagick/69597/3 "2006-09-22T16:11:21Z")

</div>

That works. I wasn’t aware of the way binary IO was done in Ruby.  
Thanks!

-Szymon
