0

I've been looking at this for a couple of days now and haven't found a solution. Is there a way to upload a file using OAuth-Ruby?

I am working with a REST system that protects their resource with oauth. I am building a test tool using ruby and oauth-ruby to make it easier to upload test data to the system. But I can't get around to upload files to the resources.

When I send a normal request, everything works but adding a file as a parameter makes the signature invalid.

Example:

 @access_token.post("http://.../imageresource", {:name=>"awesome cat"}, {'Content-Type' => 'multipart/form-data'})

works but gives me:

 <error>
    <message>images/POST: Request has no file data</message>
 </error>

I am not sure how to add a file to the post.

Any thoughts on this?

Thanks,

Jonas Söderström
  • 4,856
  • 2
  • 36
  • 45
  • @the-elite-gentleman Oauth is used for authorization not authentication. From oauth.net - "An open protocol to allow secure API authorization in a simple and standard method from desktop and web applications." I have updated the question to clarify – Jonas Söderström Mar 29 '10 at 10:51
  • correct....sorry, I tend to confuse authentication and authorization. – Buhake Sindi Mar 29 '10 at 12:04
  • Sorry, I'm not a Ruby person, but are you adding file data to your POST request? Can you check the HTTP Post request to see if your file data has been mimed and send to Http post? (or am I not clear?) – Buhake Sindi Mar 29 '10 at 12:07

2 Answers2

1

I know this is old but I'm looking to do this too, this looks like it could do the trick.

Actually there's a question ruby-how-to-post-a-file-via-http-as-multipart-form-data that has an example.

Community
  • 1
  • 1
Tom
  • 43,583
  • 4
  • 41
  • 61
0

This is either impossible to do with the oauth gem or exceedingly difficult. Either way, I don't know of any way to do it using that gem.

It can be done trivially with my signet gem as long as you have a handy way to construct a valid multipart request body. The construction of such a request body is out-of-scope of an OAuth gem, but should be pretty easy to do with most HTTP clients. The httpadapter gem can then translate the request into a form that signet can sign. Let me know if your preferred HTTP client isn't supported by httpadapter and I'll get that resolved immediately.

See the second example on the fetch_protected_resource method to get an idea for how this might be done.

Bob Aman
  • 32,839
  • 9
  • 71
  • 95
  • Hi Bob! Sound Great and I will look into it. I haven't been working with Ruby and Oauth for a while now so it might take a while before I go round looking at it, but from what I can read here it sounds very interesting. Promise to get back to you. (And If I don't just send a message in a few weeks, that'll get me moving) – Jonas Söderström Nov 24 '10 at 19:38