1

I have a rails 3 app where I am using the 'face' gem to reference the Face.com API. The api method takes a parameter of the form:

:file => File.new(path_to_file, 'rb')

which works.

I am trying to change the flow of the app so that the file can be uploaded via a form, do some work with RMagick and then make the API call, all without saving the file to disk.

I can generate the RMagick 'Image' with

image = Magick::Image.from_blob(upload_image_field.read)

I can then manipulate the file with RMagick and even save the results into the database with:

self.data = image.to_blob #normally 'upload_image_field.read' if not using RMagick

My problem is that I can't change the image file (or the blob) into something that the API will recognize (without saving it to disk and then referencing the file on disk).

For example using this in the API method fails:

:file => image.to_blob 

How do I convert he blob into the same format as

File.new(path_to_file, 'rb')

Thanks

1 Answer 1

1

OK, I could be wrong on this one... but I wanted to dig this up. Unfortunately, you just have to live with saving it as a file. The reason is because the API makes an HTTP POST. Unfortunately, this needs to be a file.

References from: [https://github.com/rociiu/face/tree/master/lib/face]:

recognition.rb:

def faces_detect(opts={})
    opts.assert_valid_keys(:urls, :file, :detector, :attributes, :callback, :callback_url)
    make_request(:faces_detect, opts)
end

utils.rb:

def make_request(api_method, opts={})
   ....
    response = JSON.parse( RestClient.post(API_METHODS[ api_method ], opts.merge(api_crendential)).body )
   ....
  end

So, why is it a problem to save to a file then?

Sign up to request clarification or add additional context in comments.

5 Comments

I was trying to eliminate extra writes to the hard drive.
I figured. Could you write to a ramdrive to increase performance?
Honestly, I have no idea. It would probably be easier for me to roll my own Face.com api which does it with post data.
OK, so finally the ramdrive idea was really easy and that's what I am using now. Thanks!
This blows my mind. I was wondering why there weren't any examples showing up of using blob data in memory for rmagick transforms...

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.