Module: Multipartable
- Included in:
- Bluevia::Utils::Multipart
- Defined in:
- lib/multipartable.rb
Overview
require ‘parts’
Constant Summary collapse
- DEFAULT_BOUNDARY =
"-----------RubyMultipartPost"
Instance Method Summary collapse
Instance Method Details
#initialize(path, params, headers = {}, boundary = DEFAULT_BOUNDARY) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/multipartable.rb', line 4 def initialize(path, params, headers={}, boundary = DEFAULT_BOUNDARY) super(path, headers) parts = params.map {|k,v| Parts::Part.new(boundary, k, v)} parts << Parts::EpiloguePart.new(boundary) ios = parts.map{|p| p.to_io } self.set_content_type("multipart/form-data", { "boundary" => boundary }) # smoking area # content_length is invalid and it deletes 2 bytes per part in multipart self.content_length = parts.inject(-2) {|sum,i| sum + (i.length + 2)} self.body_stream = CompositeReadIO.new(*ios) end |