Module: HTTPX::Plugins::Multipart
- Defined in:
- lib/httpx/plugins/multipart.rb,
lib/httpx/plugins/multipart/part.rb,
lib/httpx/plugins/multipart/decoder.rb,
lib/httpx/plugins/multipart/encoder.rb,
lib/httpx/plugins/multipart/mime_type_detector.rb
Overview
This plugin adds support for passing http-form_data objects (like file objects) as “multipart/form-data”;
HTTPX.post(URL, form: form: { image: HTTP::FormData::File.new("path/to/file")})
Defined Under Namespace
Modules: FormTranscoder, MimeTypeDetector, Part, RequestBodyMethods, ResponseMethods Classes: Decoder, Encoder, FilePart
Constant Summary collapse
- MULTIPART_VALUE_COND =
lambda do |value| value.respond_to?(:read) || (value.respond_to?(:to_hash) && value.key?(:body) && (value.key?(:filename) || value.key?(:content_type))) end
Class Method Summary collapse
Class Method Details
.load_dependencies ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/httpx/plugins/multipart.rb', line 25 def load_dependencies(*) # :nocov: begin unless defined?(HTTP::FormData) # in order not to break legacy code, we'll keep loading http/form_data for them. require "http/form_data" warn "httpx: http/form_data is no longer a requirement to use HTTPX :multipart plugin. See migration instructions under" \ "https://os85.gitlab.io/httpx/wiki/Multipart-Uploads.html#notes. \n\n" \ "If you'd like to stop seeing this message, require 'http/form_data' yourself." end rescue LoadError end # :nocov: require "httpx/plugins/multipart/encoder" require "httpx/plugins/multipart/decoder" require "httpx/plugins/multipart/part" require "httpx/plugins/multipart/mime_type_detector" end |
.normalize_keys(key, value, &block) ⇒ Object
21 22 23 |
# File 'lib/httpx/plugins/multipart.rb', line 21 def normalize_keys(key, value, &block) Transcoder.normalize_keys(key, value, MULTIPART_VALUE_COND, &block) end |