Uploads things to Amazon S3 webservices using the “aws” library (aws gem). In order for CarrierWave to connect to Amazon S3, you’ll need to specify an access key id, secret key and bucket
CarrierWave.configure do |config| config.s3_access_key_id = "xxxxxx" config.s3_secret_access_key = "xxxxxx" config.s3_bucket = "my_bucket_name" end
The AWS::S3Interface is used directly as opposed to the normal AWS::S3::Bucket et.al. classes. This gives much improved performance and avoids unnecessary requests.
You can set the access policy for the uploaded files:
CarrierWave.configure do |config| config.s3_access_policy = 'public-read' end
The default is ‘public-read’. For more options see:
docs.amazonwebservices.com/AmazonS3/latest/RESTAccessPolicy.html#RESTCannedAccessPolicies
For backwards compatability with the original aws-s3 library, if the old
config.s3_access is set it will be converted to the
appropriate access policy:
No one else has any access rights.
The anonymous principal is granted READ access. If this policy is used on an object, it can be read from a browser with no authentication.
The anonymous principal is granted READ and WRITE access.
Any principal authenticated as a registered Amazon S3 user is granted READ access.
You can change the generated url to a cnamed domain by setting the cnamed config:
CarrierWave.configure do |config| config.s3_cnamed = true config.s3_bucket = 'bucketname.domain.tld' end
Now the resulting url will be
http://bucketname.domain.tld/path/to/file
instead of
http://bucketname.domain.tld.s3.amazonaws.com/path/to/file
# File lib/carrierwave/storage/s3.rb, line 196 def connection @connection ||= Aws::S3Interface.new( uploader.s3_access_key_id, uploader.s3_secret_access_key, :multi_thread => uploader.s3_multi_thread ) end
Do something to retrieve the file
@param [String] identifier uniquely identifies the file
uniquely identifies the file
the stored file
# File lib/carrierwave/storage/s3.rb, line 192 def retrieve!(identifier) CarrierWave::Storage::S3::File.new(uploader, self, uploader.store_path(identifier)) end
Store the file on S3
the file to store
the stored file
# File lib/carrierwave/storage/s3.rb, line 176 def store!(file) f = CarrierWave::Storage::S3::File.new(uploader, self, uploader.store_path) f.store(file) f end