Can paperclip read photo geometry off an S3 bucket?

会有一股神秘感。 提交于 2019-12-04 01:05:31
Trip

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

This works for s3 and local

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

I had more or less exactly the same issue, but none of the answers here worked for me, but this did:

# 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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!