Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent timeout errors when storing files
According to aws-ruby's maintainer upload timeouts typically occur because the content length couldn't be determined directly. The fix is fairly simple, just pass a path to the file instead of the file data and the gem will open it in binary mode itself. An integration test (and all of the support around that) had to be put in place to maintain confidence about the test.
- Loading branch information
Showing
6 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
S3_BUCKET_NAME=BUCKET_NAME | ||
S3_ACCESS_KEY=YOUR_KEY | ||
S3_SECRET_ACCESS_KEY=YOUR_KEY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
*.gem | ||
.bundle | ||
.config | ||
.env | ||
Gemfile.lock | ||
bin | ||
vendor | ||
uploads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'spec_helper' | ||
|
||
if ENV['S3_BUCKET_NAME'] | ||
describe 'Storing Files' do | ||
before(:all) do | ||
CarrierWave.configure do |config| | ||
config.storage = :aws | ||
config.aws_bucket = ENV['S3_BUCKET_NAME'] | ||
config.aws_acl = :public_read | ||
|
||
config.aws_credentials = { | ||
access_key_id: ENV['S3_ACCESS_KEY'], | ||
secret_access_key: ENV['S3_SECRET_ACCESS_KEY'] | ||
} | ||
end | ||
end | ||
|
||
it 'uploads the file to the configured bucket' do | ||
image = File.open('spec/fixtures/image.png', 'r') | ||
uploader = Class.new(CarrierWave::Uploader::Base) | ||
instance = uploader.new | ||
|
||
expect { | ||
instance.store!(image) | ||
instance.retrieve_from_store!('image_file.png') | ||
}.to_not raise_error | ||
end | ||
end | ||
end |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters