Commit c0b7d08c by Guillermo Vargas Committed by Jon Yurek

Use stream downloads for S3 objects as suggested by aws-sdk

documentation.

They recommend sending a block to the #read method to avoid loading
large objects into memory. See:
http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/S3Object.html
parent 6b1f6104
...@@ -393,10 +393,11 @@ module Paperclip ...@@ -393,10 +393,11 @@ module Paperclip
def copy_to_local_file(style, local_dest_path) def copy_to_local_file(style, local_dest_path)
log("copying #{path(style)} to local file #{local_dest_path}") log("copying #{path(style)} to local file #{local_dest_path}")
local_file = ::File.open(local_dest_path, 'wb') ::File.open(local_dest_path, 'wb') do |local_file|
file = s3_object(style) s3_object(style).read do |chunk|
local_file.write(file.read) local_file.write(chunk)
local_file.close end
end
rescue AWS::Errors::Base => e rescue AWS::Errors::Base => e
warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}") warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}")
false false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment