Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paperclip S3 - Can upload images but cannot view them

I'm created a Rails app running on Heroku, with Paperclip and S3. I've managed to upload images to my S3 bucket through the site (I can see them show up in my bucket on the Amazon control panel).

But when I add an Image tag i.e. <%= image_tag x.photo.url %>, I get the following html (tags omitted here), with no image displayed!

img alt="Test_tree" src="http://s3.amazonaws.com/hiphotos/ads/photos/000/000/015/original/test_tree.jpg?1344661020"

Please help! Why can't I see the images even though they're in the bucket?

Thanks so much guys

like image 436
Misrab Avatar asked Aug 11 '12 05:08

Misrab


1 Answers

Create a file a called paperclip initializer:

# config/initializers/paperclip.rb 
# We are actually setting this to 's3_domain_url', 
# so it's not a placeholder for something else. 
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'

Or you could also place this inside production.rb:

config.paperclip_defaults = {
    :storage => :s3,
    :s3_credentials => {
        :bucket => ENV['S3_BUCKET_NAME'],
        :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
        :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
    },
    :url =>':s3_domain_url',
    :path => '/:class/:attachment/:id_partition/:style/:filename',
}
like image 148
Zorayr Avatar answered Sep 20 '22 19:09

Zorayr