Using carrierwave for our uploaders, we get a couple of Excon errors each week from our production app. For example:
Excon::Errors::BadRequest: Expected(200) <=> Actual(400 Bad Request) excon.error.response :body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>IncompleteBody</Code><Message>The request body terminated unexpectedly</Message>
We've started wrapping the uploading process in a retry block and it always seems to work fine after another try, but I'm wondering if there is a better solution, as this becomes unwieldy after a while. It seems to me like these errors ought to be handled at a lower level. Is there a better way to handle these issues?
Here's our production configuration:
config.storage = :fog
config.root = Dir.tmpdir
config.cache_dir = 'carrierwave'
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
aws_secret_access_key: ENV['AWS_ACCESS_KEY'],
}
config.fog_directory = ENV['AWS_S3_BUCKET']
config.fog_public = false
config.fog_authenticated_url_expiration = 7.days.to_i
config.enable_processing = true
And we're using gem versions:
fog (1.27.0)
carrierwave (0.10.0)
excon (0.43.0)
It started working again after I wrote my initializer like this, after overcoming a couple of problems, I think AWS endpoints have changed:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => ENV['S3_KEY'],
:aws_secret_access_key => ENV['S3_SECRET'],
:endpoint => "https://s3.amazonaws.com",
:region => ENV['S3_REGION']
}
config.fog_directory = ENV['S3_BUCKET']
end
Also, I thought my region was "us-west-2", looking at my AWS administration console, but it only started working when I changed to "eu-west-1".
Later I realized it is not a good idea to specify that endpoint, in fact it is better to leave it in this situation. Anyways, changing to carrierwave-aws as pointed by lobati solved the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With