可以回形针读取照片几何关的S3桶? [英] Can paperclip read photo geometry off an S3 bucket?

查看:186
本文介绍了可以回形针读取照片几何关的S3桶?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读照片的几何关我的S3容器。

当它在我的地方,这个作品:

 高清photo_geometry(样式=:原创)
  @geometry || = {}
  @geometry [风格] || =回形针:: Geometry.from_file photo.path(风格)
结束
 

但它似乎并不当我切换我的模式转移到S3。任何建议工作?

在更大的故事,是我尝试写一些code,让我找回从S3的照片,让用户裁剪它们,然后重新上传他们回到S3仍然指派的回形针。

编辑:

这是返回的错误:

 回形针:: NotIdentifiedByImageMagickError:照片/ 199 /原稿/ greatReads.png不被识别命令识别。
从/Users/daniellevine/Sites/hq_channel/vendor/gems/thoughtbot-paperclip-2.3.1/lib/paperclip/geometry.rb:24:in `from_file
从/Users/daniellevine/Sites/hq_channel/app/models/photo.rb:68:in`photo_geometry
从(IRB):1
 

解决方案

如果您正在使用S3作为存储机制,你不能用几何方法上面的(它假设一个本地文件)。回形针可以从S3文件转换为本地临时文件的回形针:: Geometry.from_file

下面是我更新code:

 高清photo_geometry(样式=:原创)
  @geometry || = {}
  @geometry [风格] || =回形针:: Geometry.from_file(photo.to_file(样式))
结束
 

I would like to read the geometry of a photo off of my S3 container.

When it's on my local, this works :

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

But it doesn't seem to work when I switch my model over to S3.. Any recommendations?

The bigger story, is I'm trying to write some code that will allow me to retrieve photos from S3, allow users to crop them, and then reupload them back to S3 still assigned by paperclip.

EDIT:

This is the error that is returned :

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

解决方案

If you're using S3 as a storage mechanism, you can't use the geometry method above (it assumes a local file). Paperclip can convert from S3 file to local TempFile with the Paperclip::Geometry.from_file:

Here is my updated code:

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

这篇关于可以回形针读取照片几何关的S3桶?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆