Question

When I try to use Cloudfront as my CDN the url incorrectly includes the bucket name such as

cloudfronturl.net/bucketname/pathToImage

instead of

cloudfronturl.net/pathToImage

on my image model

:s3_credentials => {
    :bucket            => ENV['AWS_BUCKET'],
    :access_key_id     => ENV['AWS_ACCESS_KEY_ID'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
    :url => ':s3_domain_url',
    :s3_host_name => ENV['CLOUDFRONT_URL']
}

I could try using a gsub on the image urls to replace ['AWS_BUCKET']+"/" but is there a way to configure my cloudfront or paperclip to do this automatically?

Was it helpful?

Solution

This was a pretty silly mistake. The url, path and host alias need to go on the same level as the s3_credentials

:url => ':s3_alias_url',
:s3_host_alias => ENV['CLOUDFRONT_URL'],
:path => ":attachment/:id/:style.:extension",

:s3_credentials => {
    :bucket            => ENV['AWS_BUCKET'],
    :access_key_id     => ENV['AWS_ACCESS_KEY_ID'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']


}

OTHER TIPS

Seems as if your not specifying a path within your Paperclip config. You may need something like this

 path: '/images/folder_name/:id/:style.:extension',

This is what i do and have never encountered the issue you specify with Cloudfront, i use it all the time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top