Created
June 9, 2011 11:10
-
-
Save christineyen/1016536 to your computer and use it in GitHub Desktop.
Using the multipart-post gem to POST a file to Crocodoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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