class HTTP::FormData::Multipart
‘multipart/form-data` form data.
def self.generate_boundary
-
(String)-
Other tags:
- Api: - public
def self.generate_boundary ("-" * 21) << SecureRandom.hex(21) end
def content_type
-
(String)-
Other tags:
- Api: - public
def content_type "#{@content_type}; boundary=#{@boundary}" end
def glue
-
(String)-
Other tags:
- Api: - private
def glue @glue ||= "--#{@boundary}#{CRLF}" end
def initialize(data, boundary: self.class.generate_boundary, content_type: DEFAULT_CONTENT_TYPE)
-
content_type(String) -- MIME type for the Content-Type header -
boundary(String) -- custom boundary string -
data(Enumerable, Hash, #to_h) -- form data key-value pairs
Other tags:
- Api: - public
Other tags:
- Example: With custom content type -
Example: Basic form data -
def initialize(data, boundary: self.class.generate_boundary, content_type: DEFAULT_CONTENT_TYPE) @boundary = boundary.to_s.freeze @content_type = content_type @io = CompositeIO.new(parts(data).flat_map { |part| [glue, part] } << tail) end
def parts(data)
-
(Array)-
Other tags:
- Api: - private
def parts(data) FormData.ensure_data(data).flat_map do |name, values| Array(values).map { |value| Param.new(name, value) } end end
def tail
-
(String)-
Other tags:
- Api: - private
def tail @tail ||= "--#{@boundary}--#{CRLF}" end