Skip to content

Instantly share code, notes, and snippets.

@whalec
Created September 18, 2011 14:53
Show Gist options
  • Save whalec/1225139 to your computer and use it in GitHub Desktop.
Save whalec/1225139 to your computer and use it in GitHub Desktop.
require 'net/http/post/multipart'
def file=(_file)
url = URI.parse(<Your endpoint>)
File.open(_file) do |f|
req = Net::HTTP::Post::Multipart.new url.path, "file" => UploadIO.new(f, "image/jpeg", "filename")
res = Net::HTTP.start(url.host, url.port) do |http|
http.request(req)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment