Last active
June 27, 2020 12:15
-
-
Save binarymason/be003bbce617c471497efd28148e67a7 to your computer and use it in GitHub Desktop.
upload multipart/form-data with net http
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
| uri = URI("#{ODM}/task/new/upload/#{oid}") | |
| request = Net::HTTP::Post.new(uri) | |
| form_data = [ | |
| ['images', attachment.tempfile, { filename: attachment.original_filename, content_type: attachment.content_type }] | |
| ] | |
| request.set_form form_data, 'multipart/form-data' | |
| response = Net::HTTP.start(uri.hostname, uri.port) do |http| # pay attention to use_ssl if you need it | |
| http.request(request) | |
| end | |
| JSON.parse(response.body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment