class Hurley::Multipart::FilePart
Represents a part to be filled from file IO.
Constants
- CID_FORMAT
- DEFAULT_DISPOSITION
- DEFAULT_TR_ENCODING
- FOOT
- HEAD_FORMAT
Attributes
length[R]
Public Class Methods
new(boundary, name, io, header)
click to toggle source
# File lib/hurley/multipart.rb, line 120 def initialize(boundary, name, io, header) 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(header) : header) @length = @head.bytesize + file_length + FOOT.length @io = CompositeReadIO.new(@length, StringIO.new(@head), io, StringIO.new(FOOT)) end
Private Instance Methods
build_head(boundary, name, filename, type, content_len, header)
click to toggle source
# File lib/hurley/multipart.rb, line 132 def build_head(boundary, name, filename, type, content_len, header) content_id = if cid = header[:content_id] CID_FORMAT % cid end HEAD_FORMAT % [ boundary, header[:content_disposition] || DEFAULT_DISPOSITION, name.to_s, filename.to_s, content_len.to_i, content_id, header[:content_type] || type, header[:content_transfer_encoding] || DEFAULT_TR_ENCODING, ] end