class Google::Apis::Core::UploadIO
Extension of Hurley's UploadIO to add length accessor
Constants
- OCTET_STREAM_CONTENT_TYPE
Public Class Methods
from_file(file_name, content_type: nil)
click to toggle source
Create a new instance given a file path @param [String, File] file_name
Path to file
@param [String] content_type
Optional content type. If nil, will attempt to auto-detect
@return [Google::Apis::Core::UploadIO]
# File lib/google/apis/core/upload.rb, line 42 def self.from_file(file_name, content_type: nil) if content_type.nil? type = MIME::Types.of(file_name) content_type = type.first.content_type unless type.nil? || type.empty? end new(file_name, content_type || OCTET_STREAM_CONTENT_TYPE) end
from_io(io, content_type: OCTET_STREAM_CONTENT_TYPE)
click to toggle source
Wraps an IO stream in UploadIO @param [#read] io
IO to wrap
@param [String] content_type
Optional content type.
@return [Google::Apis::Core::UploadIO]
# File lib/google/apis/core/upload.rb, line 56 def self.from_io(io, content_type: OCTET_STREAM_CONTENT_TYPE) new(io, content_type) end
Public Instance Methods
length()
click to toggle source
Get the length of the stream @return [Fixnum]
# File lib/google/apis/core/upload.rb, line 32 def length io.respond_to?(:length) ? io.length : File.size(local_path) end