I have a an image file stored on S3. I want to upload that file as form data to a remote site.
Controller line:
response = RestClient.post("#{BASE_URL}/processImage?language=#{LANGUAGE}&exportFormat=txt", :upload => { :file => File.new(asset.avatar.url) })
The asset.avatar.url is a paperclip stored file sitting on S3. It's there. It's publicly accessible.
But I keep getting Errno::ENOENT (No such file or directory) with the url...that works!
I'm probably missing something simple here. Anyone have any ideas?
** EDIT: SOLVED **
I used open-uri, then just used open(). It still downloads to the server, but at least it works. And visually it looks simpler. =)
Here's the fix:
require 'open-uri'
response = RestClient.post("#{BASE_URL}/processImage?language=#{LANGUAGE}&exportFormat=txt", :upload => { :file => open(asset.avatar.url) })
Open-uri is part of ruby, so you don't need to install a gem (ie: rest-client) Just require it in your code.
I thought I'd need a .read in there somewhere, but it seems to work fine without it.
You need to download the file/contents before posting it with RestClient. File.new takes a filepath as argument, not an url.