简体   繁体   中英

Heroku not showing uploaded photos using Paperclip and AWS

I'm using paperclip to load photos to a heroku site. I don't get any errors and my object is created but I don't have the photo. The gem versions I'm using are:

gem 'paperclip', '~> 4.3', '>= 4.3.6'
gem 'aws-sdk', '< 2.0'

My config settings are all correct and I'm on Oregon region so I've set the AWS_REGION to 'us-west-2'. I believe my production.rb is set up correctly,

config.paperclip_defaults = {
  storage: :s3,
  s3_credentials: {
    bucket: ENV.fetch('S3_BUCKET_NAME'),
    access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
    secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
    s3_region: ENV.fetch('AWS_REGION'),
  }
}

And my company model that should have the photo is

class Company < ActiveRecord::Base
  has_attached_file :logo_image, styles: { medium: "300x300>", 
                                           thumb: "100x100>" }, 
                    :default_url => ActionController::Base.helpers.asset_path("noimage1.jpg")

In my heroku logs:

[paperclip] saving /companies/logo_images/000/000/743/original/baking.jpg
[AWS S3 200 0.218362 0 retries] put_object(:acl=>:public_read,
    :bucket_name=>"mybucketname", :content_length=>64071,
    :content_type=>"image/jpeg",
    :data=>Paperclip::UploadedFileAdapter: baking.jpg,
    :key=>"companies/logo_images/000/000/743/original/baking.jpg")

I'm rendering the image to my show page this way:

<%= image_tag(@company.logo_image.url(:medium)) %>

It looks to me my photo is saving to the bucket but for some reason it's no rendering to the page.

I solved it by adding url and path attributes to my config.paperclip_defaults in my production.rb

url: ":s3_domain_url",
path: ":class/:id.:style.:extension",

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM