简体   繁体   English

活动存储未保存到 S3

[英]Active Storage not saving to S3

I have been setting my active storage really boilerplate.我一直在设置我的活动存储真的样板。 I do not know why its overriding my :amazon setting with :local我不知道为什么它用: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

in my view在我看来

#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">

So the problem that after I upload something it saving the file as if it was local所以问题是,在我上传某些内容后,它会将文件保存为本地文件

I am not sure where to look我不知道在哪里看

Thanks for all the help感谢所有的帮助

Make sure you have the below in config/environments/development.rb确保您在config/environments/development.rb中有以下内容

config.active_storage.service = :amazon

You can also try the following and check the URL, if it loads a S3 URL everything is working.您还可以尝试以下操作并检查 URL,如果它加载 S3 URL 一切正常。

special.main_image..service_url

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM