【问题标题】:Paperclip : wrong bucket being used from yml回形针:从 yml 使用了错误的存储桶
【发布时间】:2013-06-19 17:18:36
【问题描述】:

这曾经奏效过,至少我相信。

出于某种原因,在我的开发环境中,甚至暂存环境中,Paperclip 使用的是我的生产存储桶而不是开发存储桶。

这是用户模型中与之相关的部分

has_attached_file :avatar,
                    storage: :s3,
                    s3_credentials: "#{Rails.root}/config/s3.yml",
                    s3_permissions: :private,
                    path: "/:style/:id/:filename",
                    s3_protocol: "https",
                    styles: { medium: "300x300#", thumb: "100x100#", icon: "26x26#" },
                    default_url: ":style/ico_missing_user.png"

这里是我的 yml 文件:

common: &common
  access_key_id: <%= ENV['S3_KEY'] %>
  secret_access_key: <%= ENV['S3_SECRET'] %>

development:
  <<: *common
  bucket: mydevbucket

staging:
  <<: *common
  bucket: mystagingbucket

production:
  <<: *common
  bucket: myprodbucket

我做错了什么?

【问题讨论】:

    标签: ruby-on-rails amazon-s3 paperclip


    【解决方案1】:

    我将“load_config.rb”文件添加到我的初始化程序目录:

    load_config.rb

    S3_CONFIG = YAML.load_file("#{::Rails.root}/config/s3.yml")[Rails.env]
    

    并开始使用 S3_CONFIG 而不是 "#{Rails.root}/config/s3.yml"

    has_attached_file :avatar,
                        storage: :s3,
                        s3_credentials: S3_CONFIG,
                        s3_permissions: :private,
                        path: "/:style/:id/:filename",
                        s3_protocol: "https",
                        styles: { medium: "300x300#", thumb: "100x100#", icon: "26x26#" },
                        default_url: ":style/ico_missing_user.png"
    

    上面的解决方案可以很好地设置存储桶,但是在上传文件时我开始遇到回形针问题,说 ECONN:Aborted。

    以下是我理解的工作:

      has_attached_file :avatar,
                        storage: :s3,
                        :s3_credentials => "#{Rails.root}/config/s3.yml",
                        :bucket => ENV['S3_BUCKET'],
                        s3_permissions: :private,
                        path: "/:style/:id/:filename",
                        s3_protocol: "https",
                        styles: { medium: "300x300#", thumb: "100x100#", icon: "26x26#" },
                        default_url: ":style/ico_missing_user.png"
    

    请注意,我将存储桶与凭据分开。我这样做的灵感来自rdocs 的回形针,以及下面的sample

    【讨论】:

      猜你喜欢
      • 2013-09-09
      • 2017-11-01
      • 2014-05-05
      • 2011-03-10
      • 1970-01-01
      • 2012-09-10
      • 1970-01-01
      • 2017-10-01
      • 1970-01-01
      相关资源
      最近更新 更多