2

I have just migrated from paperclip to carrierwave and managed to successfully get uploading to S3 to work locally on my machine, but after deploying the Rails application to my server (which uses Ubuntu, Passenger with nginx, was a mission getting it to work), and when i try to upload an image, it tries to save it to public/uploads/... which comes up with a permission denied error, I have looked and searched everywhere to find out why its not working, and have found nothing.

My Uploader file:

class AvatarUploader < CarrierWave::Uploader::Base
  include CarrierWave::Compatibility::Paperclip

  storage :fog

  def store_dir
    "/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end


end

fog.rb

CarrierWave.configure do |config|
  config.storage = :fog
  config.fog_credentials = {
    provider:              'AWS',                        # required
    aws_access_key_id:     '*******',                        # required
    aws_secret_access_key: '********',                        # required
    region:                'ap-southeast-2',                  # optional, defaults to 'us-east-1'
  }
  config.fog_directory  = 'publicrant'                          # required
  # config.fog_public     = false   
  config.fog_attributes = { 'Cache-Control' => "max-age=#{365.day.to_i}" } # optional, defaults to {}
end

2 Answers2

2

Ok so after hours of googling and failing miserably at finding a solution, turns out, in a production environment it did need to put the file temporary in uploads/tmp before it pushes it to S3 Bucket

0

Seems like you doesn't have read permissions for other users (o+r). Check it use command:

namei -lm <absolute path to your current/public>

and grant read permissions:

chmod o+r <directory>

In your case I think it will be /home/<user> directory.

Maxim
  • 9,701
  • 5
  • 60
  • 108