Search code examples
ruby-on-railsfile-uploadfacebook-graph-apikoala

Uploading a file to Facebook using Koala on Ruby on Rails


I followed the following blogpost to figure out how to create Facebook events remotely using my app. I've been having problems loading the images from my app, however, because I do not have images stored locally on my app, they are stored in AWS.

    @graph = Koala::Facebook::GraphAPI.new(@token)  
    picture = Koala::UploadableIO.new(@event.photo.url(:small))
    params = {
        :picture => picture,
        :name => 'Event name',
        :description => 'Event descriptio
        :start_time => datetime,
       }

is the following code I am currently using to send pictures to Facebook when Facebook events are created on my app. The problem is, however, that Rails is throwing the error: No such file or directory - http://s3.amazonaws.com/ColumbiaEventsApp/photos/21/small.jpeg?1312521889.

Does anybody who's more experienced with Rails development know if there is a way for me to treat a URL like a path to a file? The UploadableIO class expects a path to a file, and I'm struggling to figure out if there's a way in Ruby to treat URL's like filepaths. The way that photos stored on the app can be loaded to Facebook is as follows:

picture = Koala::UploadableIO.new(File.open("PATH TO YOUR EVENT IMAGE"))

if that helps.

I appreciate any new insights into this issue.


Solution

  • With Koala 1.2.1 it's a very elegant solution. Here is sample code for creating an album and uploading to it from a remote, AWS link (btw this took about 30 lines in PHP w/ the PHP SDK!

    @foo = Foo.find(params[:foo_id])        
    albuminfo = @graph.put_object('me','albums', :name=>@foo.title)
    album_id = albuminfo["id"]    
    @graph.put_picture(@foo.remote_image_path,{}, album_id)