class Google::Apis::Core::FilePart

Part of a multipart request for holding arbitrary content. Modified from Hurley::Multipart::FilePart to remove Content-Disposition

@private

Constants

CID_FORMAT
DEFAULT_TR_ENCODING
HEAD_FORMAT

Attributes

length[R]

@return [Fixnum]

Length of part

Public Class Methods

new(boundary, io, header = {}) click to toggle source

@param [String] boundary

Multipart boundary

@param [Google::Apis::Core::UploadIO] io

IO stream

@param [Hash] header

Additional headers
# File lib/google/apis/core/multipart.rb, line 75
def initialize(boundary, io, header = {})
  file_length = io.respond_to?(:length) ? io.length : File.size(io.local_path)

  @head = build_head(boundary, io.content_type, file_length,
                     io.respond_to?(:opts) ? io.opts.merge(header) : header)

  @length = @head.bytesize + file_length + FOOT.length
  @io = Hurley::CompositeReadIO.new(@length, StringIO.new(@head), io, StringIO.new(FOOT))
end

Private Instance Methods

build_head(boundary, type, content_len, header) click to toggle source

Construct the header for the part

@param [String] boundary

Multipart boundary

@param [String] type

Content type for the part

@param [Fixnum] content_len

Length of the part

@param [Hash] header

Headers for the part
# File lib/google/apis/core/multipart.rb, line 97
def build_head(boundary, type, content_len, header)
  content_id = ''
  if header[:content_id]
    content_id = sprintf(CID_FORMAT, header[:content_id])
  end
  sprintf(HEAD_FORMAT,
          boundary,
          content_len.to_i,
          content_id,
          header[:content_type] || type,
          header[:content_transfer_encoding] || DEFAULT_TR_ENCODING)
end