lib/paperclip/storage/s3.rb in paperclip-4.2.0 vs lib/paperclip/storage/s3.rb in paperclip-4.2.1
- old
+ new
@@ -156,11 +156,11 @@
if @s3_server_side_encryption
@s3_server_side_encryption = @options[:s3_server_side_encryption]
end
unless @options[:url].to_s.match(/\A:s3.*url\Z/) || @options[:url] == ":asset_host"
- @options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/\A:rails_root\/public\/system/, '')
+ @options[:path] = path_option.gsub(/:url/, @options[:url]).gsub(/\A:rails_root\/public\/system/, '')
@options[:url] = ":s3_path_url"
end
@options[:url] = @options[:url].inspect if @options[:url].is_a?(Symbol)
@http_proxy = @options[:http_proxy] || nil
@@ -327,10 +327,11 @@
s3_interface.buckets.create(bucket_name)
end
def flush_writes #:nodoc:
@queued_for_write.each do |style, file|
+ retries = 0
begin
log("saving #{path(style)}")
acl = @s3_permissions[style] || @s3_permissions[:default]
acl = acl.call(self, style) if acl.respond_to?(:call)
write_options = {
@@ -355,13 +356,21 @@
write_options[:metadata] = @s3_metadata unless @s3_metadata.empty?
write_options.merge!(@s3_headers)
s3_object(style).write(file, write_options)
- rescue AWS::S3::Errors::NoSuchBucket => e
+ rescue AWS::S3::Errors::NoSuchBucket
create_bucket
retry
+ rescue AWS::S3::Errors::SlowDown
+ retries += 1
+ if retries <= 5
+ sleep((2 ** retries) * 0.5)
+ retry
+ else
+ raise
+ end
ensure
file.rewind
end
end
@@ -382,13 +391,14 @@
@queued_for_delete = []
end
def copy_to_local_file(style, local_dest_path)
log("copying #{path(style)} to local file #{local_dest_path}")
- local_file = ::File.open(local_dest_path, 'wb')
- file = s3_object(style)
- local_file.write(file.read)
- local_file.close
+ ::File.open(local_dest_path, 'wb') do |local_file|
+ s3_object(style).read do |chunk|
+ local_file.write(chunk)
+ end
+ end
rescue AWS::Errors::Base => e
warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}")
false
end