首页 文章

在Active Storage Cloud 中修改映像

提问于
浏览
0

我想让用户有机会裁剪和旋转用户的图像 . 用户有很多图像,图像有一个 :image_file 附加

在开发中我使用这样的方法:

class Image

...

  def  rotate(degree)
    image =  MiniMagick::Image.new(ActiveStorage::Blob.service.send(:path_for, self.image_file.key))
    image.rotate "#{degree}"
    image.write(ActiveStorage::Blob.service.send(:path_for, self.image_file.key))
    self.image_file.blob.analyze
  end

...

end

但我无法弄清楚如何在 Cloud 中获取图像文件 .

我已经将文件下载到本地存储并进行所需的所有操作 .

现在只需更换(删除当前并创建一个具有相同名称的新文件) Cloud 中的文件(如果可能,不更改数据库记录中的任何内容),但我无法弄清楚如何使用活动存储执行此操作 .

至少我需要让 file name in the cloud 只使用裸 google-cloud-ruby

1 回答

  • 0

    要使用Ruby on Rails列出存储在 Cloud 存储桶中的文件,请参阅定义的代码示例here . 您还可以使用Ruby on Rails upload files来 Cloud 存储桶和delete files .

    此外,由于您允许客户在 Cloud 存储桶中修改其文件,因此您可以考虑使用versioning . 这将产生额外费用,但会为您的客户提供可靠性 .

    这是Ruby on Google Cloud Platform文档的链接,可能对您有所帮助 .

相关问题