class Google::Apis::Core::BaseUploadCommand

Base upload command. Not intended to be used directly @private

Constants

UPLOAD_CONTENT_LENGTH
UPLOAD_CONTENT_TYPE_HEADER
UPLOAD_PROTOCOL_HEADER

Attributes

upload_content_type[RW]

Content type of the upload material @return [String]

upload_io[RW]

Content, as UploadIO @return [Google::Apis::Core::UploadIO]

upload_source[RW]

File name or IO containing the content to upload @return [String, File, read]

Public Instance Methods

prepare!() click to toggle source

Ensure the content is readable and wrapped in an {{Google::Apis::Core::UploadIO}} instance.

@return [void] @raise [Google::Apis::ClientError] if upload source is invalid

Calls superclass method Google::Apis::Core::ApiCommand#prepare!
# File lib/google/apis/core/upload.rb, line 84
def prepare!
  super
  if streamable?(upload_source)
    self.upload_io = UploadIO.from_io(upload_source, content_type: upload_content_type)
    @close_io_on_finish = false
  elsif upload_source.is_a?(String)
    self.upload_io = UploadIO.from_file(upload_source, content_type: upload_content_type)
    @close_io_on_finish = true
  else
    fail Google::Apis::ClientError, 'Invalid upload source'
  end
end
release!() click to toggle source

Close IO stream when command done. Only closes the stream if it was opened by the command.

# File lib/google/apis/core/upload.rb, line 98
def release!
  upload_io.close if @close_io_on_finish
end

Private Instance Methods

streamable?(upload_source) click to toggle source
# File lib/google/apis/core/upload.rb, line 104
def streamable?(upload_source)
  upload_source.is_a?(IO) || upload_source.is_a?(StringIO) || upload_source.is_a?(Tempfile)
end