我在我的项目中有以下文件。
config/storage.yml
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
google:
service: GCS
credentials: <%= Rails.root.join("google-cloud-storage-credentials.json") %>
project: "<%= ENV["GOOGLE_CLOUD_STORAGE_PROJECT_ID"] %>"
bucket: "matomeishi"
字符串
config/environments/development.rb
Rails.application.configure do
...
# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :google
型
config/environments/production.rb
Rails.application.configure do
...
# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :google
型
由于某种原因,当尝试附加文件时,发生以下错误。
StandardError: Missing configuration for the local Active Storage service.
Configurations available for the test and google services..
型
似乎应用程序没有考虑我的config.active_storage.service
.有人遇到同样的问题吗?这是一个错误吗?
谢谢你,谢谢
2条答案
按热度按时间7tofc5zh1#
经过一番检查,我终于找到了答案,看起来Rails使用的服务与之前的文件上传服务是一样的(可能是为了不破坏当前文件的URL)。
storage.yml
的第一个版本看起来是这样的。然后我使用local
服务上传了一些文件到GCS。字符串
local
重命名为google
,因为我认为这样更合适。我还将config/development.rb
中的配置从config.active_storage.service = :local
更改为config.active_storage.service = :google
。型
local
服务,即使它在配置中没有提到任何地方。型
原因原因是Rails首先检查
active_storage_blobs
表中的service_name
列,并且似乎使用它而不是配置中的服务集。解决方案
然后,我尝试将现有记录的所有
service_name
从local
更新为google
,看看这是否能解决问题!🎉之后,在使用ActiveStorage上传文件时,它正确地使用了
google
服务。vsikbqxv2#
添加到本地环境的
config/storage.yml
配置例如:
字符串