【问题标题】:Active Storage and Cloudinary : Using already uploaded imagesActive Storage 和 Cloudinary:使用已上传的图像
【发布时间】:2021-04-15 15:01:04
【问题描述】:

在我的种子中,我通常使用CloudinaryActive Storage 将新图片附加到我的对象:

file = URI.open("https://my_image_location")
model_instance.photo.attach(io: file, filename: "file_name")

问题是:每次我们运行种子时,Active Storage 都会完成新的图像上传,而我的Cloudinary 帐户中充满了重复的图像。

我想通过将我的图像存储在 Cloudinary 上并让 Active Storage 直接使用它而不复制它来解决这个问题,但我不知道该怎么做。 (我能够回到我使用CarrierWave 的日子里,所以有点令人沮丧:/)

你知道怎么做吗?

感谢您的宝贵时间!

【问题讨论】:

    标签: ruby-on-rails cloudinary rails-activestorage


    【解决方案1】:

    公共 ID 生成由 Active Storage 处理,因此您无法选择公共 ID。这是 Active Storage 流的限制之一。

    由于这仅用于测试,因此您可以在测试完成后使用 rails shell 中的一些命令从数据库中删除所有图像。

    【讨论】:

      猜你喜欢
      • 2020-04-30
      • 1970-01-01
      • 2018-11-14
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      • 2020-04-07
      • 2020-12-18
      • 2021-05-15
      相关资源
      最近更新 更多