-
-
Notifications
You must be signed in to change notification settings - Fork 621
Image multipart upload
Joseph Page edited this page Jan 4, 2018
·
1 revision
because oauth2
is using faraday
gem to do the http request.
so we can upload image in faraday
way.
the block
passing to OAuth2::Client
is the one to Faraday::Builder
your can read faraday#advanced-middleware-usage to understand how it work.
here are two key part to upload image.
client = OAuth2::Client.new(key, secret, :site => site, :authorize_url => auth_url, :token_url => token_url) do |b| b.request :multipart b.request :url_encoded b.adapter :net_http end
begin
img = Faraday::UploadIO.new('play.gif', 'image/gif')
data = {:content => "this is a tile", :img => img}
response = token.post('api/v1/tiles/', :body => data)
print response.body, response.status
rescue OAuth2::Error => e
puts e
end