Disabling auto-bucket creation for Paperclip
If you’re using Paperclip with S3 storage and getting a BucketAlreadyExists exception, it’s because the default behavior is to attempt to auto-create your bucket if it doesn’t exist. For me at least, 99% of the time I’ve already created the bucket(s) I’ll need, which results in this exception when trying to upload a file. To disable this behavior, around line 161 in paperclip/lib/paperclip/storage.rb, change this:
@s3_bucket ||= s3.bucket(@bucket, true, @s3_permissions)
to this:
@s3_bucket ||= s3.bucket(@bucket, false, @s3_permissions)
That’s it; right_aws (the underlying gem handling all of the S3 interaction) will stop trying to auto-create your buckets. Frankly, I don’t know why it tries to (blindly?) create the bucket every time. I may (should) patch this in the future to allow you to pass :auto_create => (true|false) as an option for has_attached_file - but for now a simple edit will do.