Skip to content

Instantly share code, notes, and snippets.

@christineyen
Created June 9, 2011 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christineyen/1016536 to your computer and use it in GitHub Desktop.
Save christineyen/1016536 to your computer and use it in GitHub Desktop.
Using the multipart-post gem to POST a file to Crocodoc
# via https://github.com/nicksieger/multipart-post's README, with a tweak to force SSL
require 'net/http/post/multipart'
uri = URI.parse('https://crocodoc.com/api/v1/document/upload')
res = File.open('./tmp/filename.jpg', 'rb') do |file|
req = Net::HTTP::Post::Multipart.new(uri.path,
'file' => UploadIO.new(file, nil),
'token' => APP_CONFIG['crocodoc_token'])
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.request(req)
end
crocodoc_res = JSON.parse(res.body)
if crocodoc_res.has_key?('error')
...
else
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment