【问题标题】:ActiveStorage and hierarchy in S3S3 中的 ActiveStorage 和层次结构
【发布时间】:2018-10-11 13:56:53
【问题描述】:

我正在尝试使用 ActiveStorage 来存储我的图像。使用 Paperclip,在 S3 存储桶中,我们可以拥有 product/id_image/*.png。但使用 ActiveStorage,所有内容都位于根目录和变体文件夹中。

在 S3 上上传文件时,有什么方法可以实现类似层次结构的行为,按模型至少一个文件夹?

【问题讨论】:

标签: ruby-on-rails amazon-s3 rails-activestorage


【解决方案1】:

默认情况下活动存储不包含路径/文件夹功能,但您可以通过

覆盖该功能

model.file.attach(key: "product/id_image/filename.png", io: File.open(file), content_type: file.content_type, filename: "#{file.original_filename}")

这样做会将密钥与您要在 s3 子目录中存储文件的路径一起存储,并将其上传到 s3 中您想要的确切位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-09
    相关资源
    最近更新 更多