这是我的第一个带有Refile gem的 Rails 项目,所以我还没有完全掌握这个美妙的文件上传 gem 的所有细节。
我正在尝试配置 Refile gem,以便在生产模式下将文件上传到 Amazon S3,但在开发模式下将文件上传到文件系统。
我的 config/initializers/refile.rb 文件如下所示:
require "refile/backend/s3"
aws = {
access_key_id: Rails.application.secrets.s3_key,
secret_access_key: Rails.application.secrets.s3_secret,
bucket: "adlit",
}
Refile.cache = Refile::Backend::S3.new(prefix: "cache", **aws)
Refile.store = Refile::Backend::S3.new(prefix: "store", **aws)
end
但是当我尝试在开发中上传图像时,我收到以下错误消息:
Missing Credentials. Unable to find AWS credentials. You can configure your AWS credentials a few different ways: * Call AWS.config with :access_key_id and :secret_access_key * Export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to ENV *...
因此,我尝试通过在条件中添加配置来解决此问题:
if Rails.env.production
...
end
但这并没有解决它,我仍然在开发模式下收到上述错误消息。
有谁知道我如何配置 Refile 以在生产模式下将文件上传到 Amazon S3 并在开发模式下将文件上传到文件系统?
感谢您的帮助,
安东尼