I would like to post a new photo to a user using `Net::HTTP::multipart`
from a Heroku application to Facebook.

I have the following JSON object:

    {"message"=>"My message",
"image"=>#<ActionDispatch::Http::UploadedFile:0x00000004242490
@original_filename="neEZYMAnBI.jpg",
@content_type="application/octet-stream", @headers="Content-Disposition:
form-data; name=\"image\";
filename=\"/home/user/public/direct/fb_images/neEZYMAnBI.jpg\"\r\nContent-Type:
application/octet-stream\r\n",
@tempfile=#<File:/app/tmp/RackMultipart20110818-1-18qnwtj>>,
"method"=>"post", "access_token"=>"my_access_token", "format"=>"json"}


I tried to use:

    require 'net/http/post/multipart'

    url =
URI.parse('https://graph.facebook.com/me/photos?access_token=#{params[:access_token]}')
    File.open(params[@tempfile]) do |jpg|
      req = Net::HTTP::Post::Multipart.new url.path,
        "file" => UploadIO.new(jpg, "image/jpeg", "image.jpg")
      res = Net::HTTP.start(url.host, url.port) do |http|
        http.request(req)
      end
    end

But:

 1. It is not sending the data.
 2. I cannot find how to send the params[:message] with the file in
order to have a caption for the image.

Can someone suggest a solution?

Thanks

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to