【发布时间】:2020-07-14 03:59:23
【问题描述】:
我一直在设置我的活动存储真正样板。 我不知道为什么它用 :local
覆盖了我的 :amazon 设置rails -V #rake, version 13.0.1
ruby -v #ruby 2.6.6p146
#config/storage.yml
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
amazon:
service: S3
access_key_id: <%= ENV['S3_KEY'] %>
secret_access_key: <%= ENV['S3_SECRET'] %>
region: <%= ENV['S3_REGION'] %>
bucket: <%= ENV['S3_BUCKET_NAME'] %>
# all ENV variables are set and they return the property values
#config/environments/production.rb
config.active_storage.service = :amazon
# I checked this in the console and I
# Rails.application.config.active_storage.service
# => :amazon
#app/models/special.rb
class Special < ApplicationRecord
has_one_attached :main_image
...
end
在我看来
#app/views/specials/index.html.haml
...
= image_tag special.main_image, width: '50px' if special.main_image.present?
...
<img width="50px" src="https://nws-prod.herokuapp.com/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBZVU9IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--79f30620b94d04457f50b7fa0eb11c529ae77629/gown%20fda%203.jpg">
所以问题是,在我上传某些内容后,它会将文件保存为本地文件
我不知道去哪里看
感谢大家的帮助
【问题讨论】:
-
如果您在开发环境中运行应用程序,请在 development.rb 文件中配置它。
-
很遗憾地说这是在生产中。我也以同样的方式更改了我的#config/environments/development.rb 文件,但我似乎无法上传到 AWS
-
几个问题,你是否在保存文件后重新启动了应用程序,如果是,确定文件正在上传到本地存储路径。
-
是的,我已经多次重新启动应用程序。当我检查文件时,它指向我的本地文件,当服务器重新启动时,它在生产服务器中的图像消失了
-
您能否为您的问题添加更多细节。即附件的型号代码和访问时生成的 URL。
标签: ruby-on-rails amazon-web-services rails-activestorage