Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on Rails - OAuth 2 multipart Post (Uploading to Facebook or Soundcloud)
    text
    copied!<p>I am working on a Rails App that Uses OmniAuth to gather Oauth/OAuth2 credentials for my users and then posts out to those services on their behalf.</p> <p>Creating simple posts to update status feeds work great.. Now I am to the point of needing to upload files. Facebook says "To publish a photo, issue a POST request with the photo file attachment as multipart/form-data." <a href="http://developers.facebook.com/docs/reference/api/photo/" rel="nofollow noreferrer">http://developers.facebook.com/docs/reference/api/photo/</a></p> <p>So that is what I am trying to do:</p> <p>I have implemented the module here: <a href="https://stackoverflow.com/questions/184178/ruby-how-to-post-a-file-via-http-as-multipart-form-data">Ruby: How to post a file via HTTP as multipart/form-data?</a> to get the headers and data...</p> <pre><code>if appearance.post.post_attachment_content_type.to_s.include?('image') fbpost = "https://graph.facebook.com/me/photos" data, headers = Multipart::Post.prepare_query("title" =&gt; appearance.post.post_attachment_file_name , "document" =&gt; File.read(appearance.post.post_attachment.path)) paramsarray = {:source=&gt;data, :message=&gt; appearance.post.content} response = access_token.request(:post, fbpost, paramsarray, headers) appearance.result = response appearance.save end </code></pre> <p>I but I am getting a OAuth2::HTTPError - HTTP 400 Error</p> <p>Any assistance would be Incredible... As I see this information will also be needed for uploading files to SoundCloud also.</p> <p>Thanks,</p> <p>Mark </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload