如何在Amazon S3中自定义Rails 5.2 ActiveStorage附件的路径?

Pet*_*ese 8 ruby-on-rails amazon-s3 rails-activestorage

添加附件时如

has_one_attached :resume_attachment
Run Code Online (Sandbox Code Playgroud)

保存的文件最终位于S3存储桶的顶层.如何将它们添加到子目录?例如,我的旧回形针配置可以按型号名称分类在目录中.

Din*_*tih 5

你不能。has_one_attached此时,对于,宏只有一种可能的选择,has_many_attached:dependent. https://github.com/rails/rails/blob/master/activestorage/lib/active_storage/attached/macros.rb#L30

请参阅(也许是您投反对票的原因,但它与“直接”上传有关...):如何使用 activestorage 的直接上传上传到 S3 时指定前缀?。来自 Active Storage 主要维护者的回应。