载波+雾+ AWS S3和生产中的导轨 [英] Carrierwave + fog + aws s3 and rails in production

查看:61
本文介绍了载波+雾+ AWS S3和生产中的导轨的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从回形针迁移到了载波,并设法成功上传到S3以便在我的机器上本地工作,但是在将Rails应用程序部署到我的服务器(使用Ubuntu,Passenger和nginx的服务器)之后,将其迁移到工作),并且当我尝试上传图片时,它尝试将其保存到public/uploads....这出现了权限被拒绝的错误,我到处寻找并进行搜索以找出为什么图片不起作用,并且一无所获.

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.

我的上载器文件:

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

推荐答案

好吧,经过数小时的搜索并在寻找解决方案时惨遭失败,事实证明,在生产环境中,确实需要将文件临时放在上载/tmp中在将它推到S3桶之前

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

这篇关于载波+雾+ AWS S3和生产中的导轨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆