Oauth multipart file upload/post
Does anyone have an example of what a file post in rails would look like? Am having a hard time finding an example online, i assume it is something like @token.post(uri, {:file=>'mypic.jpg'}, {'Content-type'=>'multipart/form-data'}) but have had no luck getting this to work. Any help would be greatly appreciated. Examples of this are few and far between. Thanks
3
people have this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
-
Inappropriate?with the new gem version 0.3.2 I can!!! =)
-
Inappropriate?@tonio could you give me an example of how you did it?
thank you :) -
Inappropriate?Yes, sure:
I'm using Oauth 0.3.2 in both sides (client and provider).
In the client side I'm doing this:
response = @access_token.post("/api/upload?type=#{params[:type]}", {:title => @stream.title, :description => @stream.description, :file => @stream.file.read}, { 'Accept' => 'application/xml', 'Content-Type' => 'multipart/form-data' })
file is an attr_accessor of the model
In the provider side I'm just doing a .read to the :file param and proccess it.
Cheers,
Tonio -
This doesn't work for me... nor does it seem right. As the other post noted, the content-type always comes across as application/x-www-form-urlencoded despite the fact that you're manually setting the content type. In addition, I'm seeing the file body come across as a form post parameter, which per the OAuth spec would suggest that it should participate in the signing process, which doesn't seem right. So... I'm a bit confused on this one. Could you perhaps post more of your code - like the receiver's side? Thanks! -
Inappropriate?hmm, doesnt work for me.
tried with 0.3.2, 0.3.3 and 0.3.4 on client side (dont know which version is running on the server)
my client always sends Content-Type: application/x-www-form-urlencoded :(
but thank you for your quick response :) -
Inappropriate?the key for me was realizing that there was a multi-part gem. ..
gem install multipart
if you need more specific info, i can try to make another post later, kinda in a hurry atm -
Inappropriate?yes i use the multipart gem now as well:
req = Net::HTTP::Post.new('/tracks')
file = Net::HTTP::FileForPost.new('helloworld.mp3', 'application/octet-stream')
req.set_multipart_data({'track[asset_data]' => file})
access_token.sign!(req)
res = Net::HTTP.new('host',80).start do |http|
http.request(req)
end
works for me.
do you have a better way?
cheers
jo -
Inappropriate?nope, that is essentially what I have also.
-
Inappropriate?@token.post(uri, {:file=>'mypic.jpg'}, {'Content-type'=>'multipart/form-data'})
this call works fine with the newest oauth gem on github.
pelle or someone fixed the bug, but it is not included oauth 0.3.5 or older.
it will work with further oauth gem. (0.3.6 or newer)
or use the gem on github.
I’m happy
Loading Profile...



