使用refile gem,Ruby on Rails保存上传到amazon S3的图像细节

时间:2016-11-19 06:25:26

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

您好我正在尝试使用refile gem

将图片直接上传到S3

project.rb看起来像

class Project < ActiveRecord::Base
    has_many :photos, :class_name => "Project::Photo", dependent: :destroy
    accepts_attachments_for :photos
end

项目/ photo.rb

class Project::Photo < ActiveRecord::Base
    belongs_to :project

    attachment :file

    attr_accessible :name, :address, :created_at, :project_id, :file
    before_create :debugging_create


end

配置/初始化/ refile.rb

require "refile/s3"

aws = {
  access_key_id: "xyz",
  secret_access_key: "abc",
  region: "sa-east-1",
  bucket: "my-bucket",
}
Refile.cache = Refile::S3.new(prefix: "cache", **aws)
Refile.store = Refile::S3.new(prefix: "store", **aws)

Refile.backends的输出[图片1]

Output from Refile.backends

文件上传的参数对于photos_files [图片2]

是这样的

Params on file upload looks like this for photos_files

的问题:

  1. 无法获取并保存正在保存的数据库中的密钥 进入亚马逊S3。 Refile.backends中显示了不同的键。
  2. 如何在更新时保存新文件。目前它覆盖了现有的 文件。

0 个答案:

没有答案