views:

61

answers:

1

I want to read metadata of already uploaded JPEGs on S3. Is there a way to do that in Ruby without downloading the file locally?

The problem I am facing is that Image(Mini)Magick doesn't take a URL as a source (or at least I didn't find the right command).

Update:

This is working:

>> image = MiniMagick::Image.from_file -path_to_file-
>> image["EXIF:datetime"]
=> "2010:07:19 23:07:54"

But I didn't find a good substitude for "from_file", for URLs so something like:

>> image = MiniMagick::Image.from_url http://image_adress.com/image.jpg

doesn't work.

+1  A: 

What about using open-uri?

require 'open-uri'

image = nil
open('http://image_adress.com/image.jpg') do |file|
  image = MiniMagick::Image.from_blob(file.read) rescue nil
end
image["EXIF:datetime"] if image
John Bintz
Thanks, great! Is there a way to just read the metadata without downloading the file (saving bandwidth)?
Stefan Koenig
You could try to progressively load in just enough data from the remote location and see if MiniMagick will return what you need w/o having to load all the data. I do this with the imagesize gem -- only feed it a few KB at a time until it returns with a success or I've read the whole file.
John Bintz
ok thanks, I will try it out.
Stefan Koenig