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,
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.
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.
精彩评论