class Google::Apis::Core::BaseUploadCommand
Base upload command. Not intended to be used directly @private
Constants
- CONTENT_TYPE_HEADER
- 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 IO 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 50 def prepare! super if streamable?(upload_source) self.upload_io = upload_source @close_io_on_finish = false elsif self.upload_source.is_a?(String) self.upload_io = File.new(upload_source, 'r') if self.upload_content_type.nil? type = MiniMime.lookup_by_filename(upload_source) self.upload_content_type = type && type.content_type end @close_io_on_finish = true else fail Google::Apis::ClientError, 'Invalid upload source' end if self.upload_content_type.nil? || self.upload_content_type.empty? self.upload_content_type = 'application/octet-stream' 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 71 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 77 def streamable?(upload_source) upload_source.is_a?(IO) || upload_source.is_a?(StringIO) || upload_source.is_a?(Tempfile) end