简体   繁体   中英

Rails 6.1 not supporting multiple AWS S3 buckets in ActiveStorage

I have recently updated Rails to 6.1 to support multiple buckets uploads in ActiveStorage. However, after upgrading, updating ActiveStorage, deleting everything and reinstalling again, it still does not work. I followed this guide. I also followed this . Here's my implementation:

# storage.yaml
amazon_contracts:
  service: S3
  access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
  secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
  region: sa-east-1
  bucket: contracts-raw-ac1

amazon_templates:
  service: S3
  access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
  secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
  region: sa-east-1
  bucket: templates-raw-ac1
# development.rb (default service to be used)
config.active_storage.service = :amazon_contracts
# template.rb
has_one_attached :template, service: :amazon_templates
# contract.rb
has_many_attached :contracts, service: :amazon_contracts

However, both the template and contract uploads go directly to the contracts bucket. I have tried removing the default service from the development.rb , but I get cannot get name of nil Class error. Any help is very much appreciated.

I followed your setup almost exactly, and it worked as intended. The only way I could replicate is if I redefined the attachment has_one/has_many relationships later in the model files. Is it possible you've done something like this?

# template.rb
has_one_attached :template, service: :amazon_templates

# ...
# ... potentially many lines of code ...
# ...

has_one_attached :template

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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