您好我正在尝试使用 refile gem 将图像直接上传到 S3
project.rb 看起来像
class Project < ActiveRecord::Base
has_many :photos, :class_name => "Project::Photo", dependent: :destroy
accepts_attachments_for :photos
end
项目/照片.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]
photos_files 文件上传的参数如下所示 [图 2]
问题:
- 无法获取并保存正在保存到亚马逊 S3 的数据库中的密钥。Refile.backends 中显示了不同的键。
- 如何在更新时保存新文件。目前它会覆盖现有文件。