class Aws::S3::FileUploader
@api private
Constants
- ONE_HUNDRED_MEGABYTES
Attributes
client[R]
@return [Client]
multipart_threshold[R]
@return [Integer] Files larger than or equal to this in bytes are uploaded
using a {MultipartFileUploader}.
Public Class Methods
new(options = {})
click to toggle source
@param [Hash] options @option options [Client] :client @option options [Integer] :multipart_threshold (104857600)
# File lib/aws-sdk-s3/file_uploader.rb, line 15 def initialize(options = {}) @options = options @client = options[:client] || Client.new @multipart_threshold = options[:multipart_threshold] || ONE_HUNDRED_MEGABYTES end
Public Instance Methods
upload(source, options = {})
click to toggle source
@param [String, Pathname, File, Tempfile] source The file to upload. @option options [required, String] :bucket The bucket to upload to. @option options [required, String] :key The key for the object. @option options [Proc] :progress_callback
A Proc that will be called when each chunk of the upload is sent. It will be invoked with [bytes_read], [total_sizes]
@return [void]
# File lib/aws-sdk-s3/file_uploader.rb, line 36 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-s3/file_uploader.rb, line 46 def open_file(source) if String === source || Pathname === source File.open(source, 'rb') { |file| yield(file) } else yield(source) end end
put_object(source, options)
click to toggle source
# File lib/aws-sdk-s3/file_uploader.rb, line 54 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
single_part_progress(progress_callback)
click to toggle source
# File lib/aws-sdk-s3/file_uploader.rb, line 63 def single_part_progress(progress_callback) proc do |_chunk, bytes_read, total_size| progress_callback.call([bytes_read], [total_size]) end end