2017-04-16 83 views
0

我正在使用Heroku和Amazon AWS(S3)在線遷移我的應用程序,並遇到了我的profilepic模型的奇怪錯誤。使用Amazon S3時出現回形針錯誤

此模型管理配置文件圖片。它由2個回形針附件和一些其他字段組成,並取決於另一個型號Professionnel

下面是該模型:

class Profilepic < ApplicationRecord 

    belongs_to :professionnel 

    has_attached_file :image, styles: { original: "6000x6000", editable: "1200x1200", thumbnail: "400x400#"} 
    validates_attachment :image, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }, size: {less_than: 10.megabytes} 

    has_attached_file :finalimage, styles: { medium: "500x500", small: "200x200"}, processors: [:cropper] 

    attr_accessor :crop_x, :crop_y, :crop_w, :crop_h 

end 

第一附接:圖像是由用戶上載的圖像。第二圖像(:finalimage)是

一切局部正常使用

雖然,當圖像被上傳下面的代碼位被返回Professionnel用戶編輯它(與cropper.js)之後的裁剪後的圖像回形針::錯誤:: NotIdentifiedByImageMagickError

的觸發此錯誤代碼位是:

nouvelleppic.ratiolongdivlarg = Paperclip::Geometry.from_file(nouvelleppic.image.path(:original)).width/Paperclip::Geometry.from_file(nouvelleppic.image.path(:original)).height 

在此位的代碼,我discove在Paperclip幾何函數的幫助下響應寬高比。

不知道什麼是錯的。它確實在本地工作,我正在查詢此後:圖像被成功保存到我的S3桶(我在S3控制檯檢查)

我需要這個比例創建的視圖,將允許用戶裁剪圖像和轉它進入:finalimage。這真的很有趣,它遷移到Heroku/S3時不起作用,因爲它是一個來自Paperclip的簡單幾何函數。沒問題上傳...

編輯編輯

似乎找到問題:

https://github.com/thoughtbot/paperclip/issues/2198

我只是檢查了我的Heroku Cedar14 ImageMagick的版本堆:6.7.7-10 !

Version: ImageMagick 6.7.7-10 2016-11-29 Q16 http://www.imagemagick.org 

正如上面的git線程所建議的,有沒有一種方法可以在Heroku上升級ImageMagick?

此線程How can I use the latest version of Imagemagick on Heroku?似乎暗示我們可以做到這一點(第二個答案)?

回答

0

迴應你的第二個問題。你在heroku上更新Image Magic的方式是使用buildpack。就像你現在有一個Ruby buildpack你必須添加一個Image Magic buildpack。 Heroku的對圖像魔術buildpacks專用頁面:

https://elements.heroku.com/search/buildpacks?utf8=%E2%9C%93&q=imagemagick

這一個(如下圖),似乎是最流行的,但隨意瀏覽周圍: https://elements.heroku.com/buildpacks/mcollina/heroku-buildpack-imagemagick

+0

感謝您對本。這是很好的知道我可以更改ImageMagick版本。雖然我甚至不確定它會解決我的問題。將嘗試在git Thread中提到的修復。這是比我能做的更先進的Ruby,但我會試試看。 – Maxence

+0

一個愚蠢的事情:我檢查遠程存儲的圖像的尺寸。儘管模型尚未保存,然後圖像尚未用回形針處理,是否無法檢查此事件?像臨時文件? – Maxence

+0

該死的了! http://stackoverflow.com/questions/4065295/saving-the-images-dimensions-width-and-height-in-paperclip – Maxence