class Aws::S3::FileUploader

@api private

def initialize(options = {})

Options Hash: (**options)
  • :multipart_threshold (Integer) --
  • :client (Client) --

Parameters:
  • options (Hash) --
def initialize(options = {})
  @options = options
  @client = options[:client] || Client.new
  @multipart_threshold = options[:multipart_threshold] ||
                         ONE_HUNDRED_MEGABYTES
end

def open_file(source)

def open_file(source)
  if String === source || Pathname === source
    File.open(source, 'rb') { |file| yield(file) }
  else
    yield(source)
  end
end

def put_object(source, options)

def put_object(source, options)
  if (callback = options.delete(:progress_callback))
    options[:on_chunk_sent] = single_part_progress(callback)
  end
  open_file(source) do |file|
    @client.put_object(options.merge(body: file))
  end
end

def single_part_progress(progress_callback)

def single_part_progress(progress_callback)
  proc do |_chunk, bytes_read, total_size|
    progress_callback.call([bytes_read], [total_size])
  end
end

def upload(source, options = {})

Returns:
  • (void) -

Options Hash: (**options)
  • :thread_count (Integer) --
  • :progress_callback (Proc) --
  • :key (required, String) -- The key for the object.
  • :bucket (required, String) -- The bucket to upload to.

Parameters:
  • source (String, Pathname, File, Tempfile) -- The file to upload.
def upload(source, options = {})
  Aws::Plugins::UserAgent.metric('S3_TRANSFER') do
    if File.size(source) >= multipart_threshold
      MultipartFileUploader.new(@options).upload(source, options)
    else
      # remove multipart parameters not supported by put_object
      options.delete(:thread_count)
      put_object(source, options)
    end
  end
end