I think that this can help :
class FbPhotoUploader
require 'net/http/post/multipart' # multipart-post gem
require 'mime/types' #mime-types gem
require 'net/https'
def upload(path, access_token, options={})
photo = File.open(path)
params = {:access_token => access_token}
params.merge!(options)
url = URI.parse("https://graph.facebook.com/me/photos")
req = Net::HTTP::Post::Multipart.new
"#{url.path}?#{params.to_query}",
"file" => UploadIO.new(photo, mime_for_file(photo), photo.path)
n = Net::HTTP.new(url.host, url.port)
n.use_ssl = true
n.verify_mode = OpenSSL::SSL::VERIFY_NONE
n.start do |http|
http.request(req)
end
end
private
def mime_for_file(f)
m = MIME::Types.type_for(f.path.split('').last)
m.empty? ? "application/octet-stream" : m.to_s
end
end
--
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.