class Multipart::Post::Parts::FilePart
Represents a part to be filled from file IO.
def build_head(boundary, name, filename, type, content_len, opts = {})
-
opts
(Hash
) -- -
content_len
(Integer
) -- -
type
(String
) -- -
filename
(String
) -- -
name
(#to_s
) -- -
boundary
(String
) --
def build_head(boundary, name, filename, type, content_len, opts = {}) opts = opts.clone trans_encoding = opts.delete("Content-Transfer-Encoding") || "binary" content_disposition = opts.delete("Content-Disposition") || "form-data" part = String.new part << "--#{boundary}\r\n" part << "Content-Disposition: #{content_disposition}; name=\"#{name.to_s}\"; filename=\"#{filename}\"\r\n" part << "Content-Length: #{content_len}\r\n" if content_id = opts.delete("Content-ID") part << "Content-ID: #{content_id}\r\n" end if opts["Content-Type"] != nil part << "Content-Type: " + opts["Content-Type"] + "\r\n" else part << "Content-Type: #{type}\r\n" end part << "Content-Transfer-Encoding: #{trans_encoding}\r\n" opts.each do |k, v| part << "#{k}: #{v}\r\n" end part << "\r\n" end
def initialize(boundary, name, io, headers = {})
-
headers
(Hash
) -- -
io
(IO
) -- -
name
(#to_s
) -- -
boundary
(String
) --
def initialize(boundary, name, io, headers = {}) 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.merge(headers) : headers) @foot = "\r\n" @length = @head.bytesize + file_length + @foot.length @io = CompositeReadIO.new(StringIO.new(@head), io, StringIO.new(@foot)) end