mardi 26 mai 2015

Rails 4, Carrierwave-aws, images uploaded to Amazon s3 locally, but not in production (Openshift)

I have a Rails 4 application hosted on openshift. I am using carrierwave and the carrierwave-aws gem to handle image upload. When I test it locally, the images are uploaded and displayed as expected to Amazon S3. However, on production server, which is hosted on Openshift, the images are uploaded to '/uploads/images' instead of Amazon. Here are my configurations and Gemfile:

gem 'carrierwave'
gem 'carrierwave-aws'

In initializers/carrierwave.rb

#config/initializers/carrierwave.rb
CarrierWave.configure do |config|

  config.storage    = :aws
  config.aws_bucket = 'mybucketname'
  config.aws_acl    = :public_read
  config.asset_host = 'http://ift.tt/1SAV3ZN'
  config.aws_authenticated_url_expiration = 60 * 60 * 24 * 365

  config.aws_credentials = {

    # Configuration for Amazon S3
    :provider              => 'AWS',
    :access_key_id     => 'myaccessid',
    :secret_access_key => 'mysecretkey',
    :region                => 'us-west-1',
  }

   config.storage = :aws
   config.cache_dir = "#{Rails.root}/tmp/uploads"                

end

In image_uploader.rb I also put

 storage :aws

Just in case this helps: I used Fog before and locally it also works fine. However on production it gives an Excon error. After some googling I come to the conclusion that carrierwave-aws is a better choice.




Aucun commentaire:

Enregistrer un commentaire