3

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
  • can you show us what you tried that didn't work? Aug 4, 2010 at 19:00

1 Answer 1

2

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
3
  • Thanks, great! Is there a way to just read the metadata without downloading the file (saving bandwidth)? Aug 10, 2010 at 17:16
  • 1
    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
    Aug 10, 2010 at 21:04
  • @JohnBintz Is there a java library that does "progressively load"?
    – Deckard
    Apr 23, 2019 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.