回形针可以从S3铲斗中读取照片几何图形吗?

我想从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 

这适用于s3和本地

 def photo_geometry(style = :original) @geometry ||= {} photo_path = (photo.options[:storage] == :s3) ? photo.url(style) : photo.path(style) @geometry[style] ||= Paperclip::Geometry.from_file(photo_path) end 

我或多或少有完全相同的问题,但这里没有任何答案对我有用,但这样做了:

 # helper method used by the cropper view to get the real image geometry def image_geometry(style = :original) @geometry ||= {} @geometry[style] ||= Paperclip::Geometry.from_file open("https:" + image.url(style)) end