class Aws::S3::FileUploader

@api private

Constants

FIFTEEN_MEGABYTES

Attributes

client[R]

@return [Client]

multipart_threshold[R]

@return [Integer] Files larger than this in bytes are uploaded

using a {MultipartFileUploader}.

Public Class Methods

new(options = {}) click to toggle source

@option options [Client] :client @option options [Integer] :multipart_threshold Files greater than

`:multipart_threshold` bytes are uploaded using S3 multipart APIs.
# File lib/aws-sdk-resources/services/s3/file_uploader.rb, line 13
def initialize(options = {})
  @options = options
  @client = options[:client] || Client.new
  @multipart_threshold = options[:multipart_threshold] || FIFTEEN_MEGABYTES
end

Public Instance Methods

upload(source, options = {}) click to toggle source

@param [String,Pathname,File,Tempfile] source @option options [required,String] :bucket @option options [required,String] :key @return [void]

# File lib/aws-sdk-resources/services/s3/file_uploader.rb, line 30
def upload(source, options = {})
  if File.size(source) >= multipart_threshold
    MultipartFileUploader.new(@options).upload(source, options)
  else
    put_object(source, options)
  end
end

Private Instance Methods

open_file(source) { |file| ... } click to toggle source
# File lib/aws-sdk-resources/services/s3/file_uploader.rb, line 46
def open_file(source)
  if String === source || Pathname === source
    file = File.open(source, 'rb')
    yield(file)
    file.close
  else
    yield(source)
  end
end
put_object(source, options) click to toggle source
# File lib/aws-sdk-resources/services/s3/file_uploader.rb, line 40
def put_object(source, options)
  open_file(source) do |file|
    @client.put_object(options.merge(body: file))
  end
end