简体   繁体   English

使用带有carrierwave gem的多个S3存储桶

[英]Using multiple S3 buckets with carrierwave gem

I have just recently setup my rails 3.2 app to use the carrierwave gem and upload files to S3. 我刚刚设置了我的rails 3.2 app以使用carrierwave gem并将文件上传到S3。 What I don't see is the ability to use a different bucket per uploader. 我没有看到的是每个上传器使用不同桶的能力。 Does anyone know if this is a possiblity? 有谁知道这是否可能?

The bucket is specified via the fog_directory config. 存储桶是通过fog_directory配置指定的。 This configuration option is defined on the uploader and could simply be overwritten with your own method. 此配置选项在上传器中定义,可以使用您自己的方法简单地覆盖。

Just add the following to your uploader: 只需将以下内容添加到您的上传器:

def fog_directory
  # your bucket name here
end

The carrierwave wiki explains how to use a separate s3 bucket for each uploader : carrierwave wiki解释了如何为每个上传器使用单独的s3存储桶

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

Multiple buckets is not currently supported by CarrierWave. CarrierWave目前不支持多个存储桶。 You can separate files between uploaders by adding prefixes (folders) to the store_dir . 您可以通过向store_dir添加前缀(文件夹)来在上载程序之间分隔文件。 Pull requests are welcome though if this is something you'd like to work on! 如果这是您想要的工作,欢迎拉请求!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM