gpt4 book ai didi

ruby-on-rails - 回形针可以读取 S3 存储桶中的照片几何图形吗?

转载 作者:数据小太阳 更新时间:2023-10-29 06:40:50 25 4
gpt4 key购买 nike

我想从我的 S3 容器中读取照片的几何形状。

当它在我的本地时,这是有效的:

def photo_geometry(style = :original)
@geometry ||= {}
@geometry[style] ||= Paperclip::Geometry.from_file photo.path(style)
end

但是当我将模型切换到 S3 时它似乎不起作用。有什么建议吗?

更大的故事是,我正在尝试编写一些代码,允许我从 S3 检索照片,允许用户裁剪它们,然后将它们重新上传回 S3,仍然由回形针分配。

编辑:

这是返回的错误:

Paperclip::NotIdentifiedByImageMagickError: photos/199/orig/greatReads.png is not recognized by the 'identify' command.
from /Users/daniellevine/Sites/hq_channel/vendor/gems/thoughtbot-paperclip-2.3.1/lib/paperclip/geometry.rb:24:in `from_file'
from /Users/daniellevine/Sites/hq_channel/app/models/photo.rb:68:in `photo_geometry'
from (irb):1

最佳答案

如果您使用 S3 作为存储机制,则不能使用上面的几何方法(它假定为本地文件)。 Paperclip 可以使用 Paperclip::Geometry.from_file 从 S3 文件转换为本地 TempFile:

这是我更新后的代码:

def photo_geometry(style = :original)
@geometry ||= {}
@geometry[style] ||= Paperclip::Geometry.from_file(photo.to_file(style))
end

关于ruby-on-rails - 回形针可以读取 S3 存储桶中的照片几何图形吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3160788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com