设置上传器(载波) [英] Setup for an uploader (carrierwave)

查看:74
本文介绍了设置上传器(载波)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用宝石载波和雾的教程之后,我有一个图像上传器。现在,我想添加一个额外的上载器,但是很麻烦。

I have an image uploader in place following a tutorial using the gems carrierwave and fog. Now I would like to add an additional uploader but am struggling.

我已经生成了上传器( rails生成了上传器名称)。在模型文件中,我已将上传器安装到右列( mount_uploader:column_name,nameUploader )。在上载程序中,我设置了 def extension_white_list store_dir 。我也包括了(因为在本教程中,我做了同样的事情):

I have generated the uploader (rails generate uploader name). In the model file I have mounted the uploader to the right column (mount_uploader :column_name, nameUploader). In the uploader itself I have set def extension_white_list and store_dir. Also I included (since in the tutorial I did the same):

if Rails.env.production?
  storage :fog
else
  storage :file
end

现在,我遇到的问题是我不知道在哪里设置雾的规格。也就是说,在哪里指定应该上传到的Amazon存储桶。在carrier_wave初始化程序中,我已经有以下代码。但是这段代码指定了我已经实现的上传器上传到的位置。这些规格与此新的上传器不同。对于Rails.env.production,我应该在哪里/如何为新的上传程序添加这些规范?

Now where I'm stuck is that I don't know where to set the specifications for fog. That is, where to specify the Amazon bucket it should upload to. In a carrier_wave initializer I already had the code below. But this code specifies where to upload to for the uploader I had already implemented. These specifications are different for this new uploader. Where/how should I include these specs for the new uploader?

if Rails.env.production?   
  CarrierWave.configure do |config|
    config.fog_credentials = {
      :provider              => 'AWS',
      :aws_access_key_id     => ENV['S3_ACCESS_KEY'],
      :aws_secret_access_key => ENV['S3_SECRET_KEY'],
      :region                => ENV['AWS_REGION']
    }
    config.fog_directory     =  ENV['S3_BUCKET']
  end 
end


推荐答案

通过查看此Wiki页面
似乎可以覆盖每个上传者的配置

By looking at this wiki page it seems like it is possible to override the config for each uploader

class AvatarUploader < CarrierWave::Uploader::Base
  # Choose what kind of storage to use for this uploader:
  storage :fog

  # define some uploader specific configurations in the initializer
  # to override the global configuration
  def initialize(*)
    super

    self.fog_credentials = {
      :provider               => 'AWS',              # required
      :aws_access_key_id      => 'YOURAWSKEYID',     # required
      :aws_secret_access_key  => 'YOURAWSSECRET',    # required
    }
    self.fog_directory = "YOURBUCKET"
  end
end

这篇关于设置上传器(载波)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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