Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
Clone this wiki locally

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /