Class: Faraday::Parts::FilePart

Inherits:
Object
  • Object
show all
Defined in:
lib/faraday/parts/filepart.rb

Overview

monkey patch from @liluo gist.github.com/4176272

Instance Method Summary collapse

Constructor Details

#initialize(boundary, name, io) ⇒ FilePart

Returns a new instance of FilePart.



4
5
6
7
8
9
10
# File 'lib/faraday/parts/filepart.rb', line 4

def initialize(boundary, name, io) 
  file_length = io.respond_to?(:length) ?  io.length : File.size(io.local_path)    
  @head = build_head(boundary, name, io.original_filename, io.content_type, file_length,
                     io.respond_to?(:opts) ? io.opts : {}) 
  @length = @head.length + file_length
  @io = CompositeReadIO.new(StringIO.new(@head), io, StringIO.new("\r\n"))
end