Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AWS::S3 built in download_file method #9

Merged
merged 2 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/paperclip/storage/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,7 @@ def flush_deletes #:nodoc:

def copy_to_local_file(style, local_dest_path)
log("copying #{path(style)} to local file #{local_dest_path}")
::File.open(local_dest_path, 'wb') do |local_file|
s3_object(style).get do |chunk|
local_file.write(chunk)
end
end
s3_object(style).download_file(local_dest_path)
rescue Aws::Errors::ServiceError => e
warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}")
false
Expand Down
8 changes: 5 additions & 3 deletions spec/paperclip/storage/s3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,26 +443,28 @@ def counter
allow(@dummy.avatar).to receive(:s3_object).with(:thumb).and_return(@object)
allow(@object).to receive(:get).and_yield(@file.read)
allow(@object).to receive(:exists?).and_return(true)
allow(@object).to receive(:download_file).with(anything)
end

it "uploads original" do
expect(@object).to receive(:upload_file).with(
anything,
content_type: "image/png",
acl: :"public-read").and_return(true)
@dummy.avatar.reprocess!
expect(@object).to receive(:upload_file).with(
anything,
content_type: "image/jpeg",
content_type: "image/png",
acl: :"public-read").and_return(true)
@dummy.avatar.reprocess!
end

it "doesn't upload original" do
expect(@object).to receive(:upload_file).with(
anything,
content_type: "image/jpeg",
content_type: "image/png",
acl: :"public-read").and_return(true)
@dummy.avatar.reprocess!(:thumb)
@dummy.avatar.reprocess!
end
end

Expand Down