Carrierwave + fog + aws s3 and rails in production
Asked Answered
S

2

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
Shandy answered 6/3, 2015 at 6:24 Comment(0)
S
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

Shandy answered 6/3, 2015 at 9:15 Comment(0)
P
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.

Pathless answered 6/3, 2015 at 7:11 Comment(3)
permissions seem to be fine, I still have no idea what is causing the issueShandy
Check permissions to public/uploads and other sub-directoriesPathless
but if i change permissions, that will allow files to be saved in public/uploads, I want them to be saved to my S3 bucketShandy

© 2022 - 2024 — McMap. All rights reserved.