简体   繁体   中英

Paperclip on heroku with S3 - not working

I am using paperclip to handle image uploads in my Rails app. All works fine running in the development environment locally using the File Storage.

Now I am trying to get this working using S3 (because the app is to run on Heroku). I have set up a bucket and set the appropriate parameters in development.rb and production.rb as per the instructions here: https://devcenter.heroku.com/articles/paperclip-s3

When I start the server, I get the following error:

/Users/ganzogo/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/railtie/configuration.rb:85:in `method_missing': undefined method `paperclip' for #<Rails::Application::Configuration:0x007fcb8b952000> (NoMethodError)
  from /Users/ganzogo/Documents/acknowledgement/true-rails/config/environments/development.rb:41:in `block in <top (required)>'

And then it crashes.

The line referred to in the error is:

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']
  }
}

I get exactly the same error if I try to run on Heroku. Has anyone been through this and have any idea what I have missed?

It looks like you may have a typo in your configuration block. Try changing config.paperclip.defaults = {...} to config.paperclip_defaults = {...} and that should solve your problem.

We got this working on one of our live apps

The difference is you need to put the credentials into the model itself. Here's what we've got:


#app/models/image.rb
#Image Upload 
        Paperclip.options[:command_path] = 'C:\RailsInstaller\ImageMagick'
        has_attached_file :image,
                :styles => { :medium => "x300", :thumb => "x100" },
                :default_url => "*******",
                :storage => :s3,
                :bucket => '******',
                :s3_credentials => S3_CREDENTIALS


#app/config/application.rb
config.paperclip_defaults = {
            :storage => :s3,
            :s3_host_name => 's3-eu-west-1.amazonaws.com'
    }

In Heroku, you'll need to add the various environment variables to your config settings

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