简体   繁体   English

Rails 4,Heroku上的Paperclip无法识别损坏的图像

[英]Rails 4, Paperclip on Heroku does not recognize broken image

having trouble solving problem with pictures on my project. 无法解决我项目中的图片问题。

Summary: Rilas 4 hosted on Heroku using Paerclip with S3 简介:Rilas 4使用Paerclip和S3在Heroku上托管

Problem starts with having to use previously used custom uploading logic with S3. 问题始于必须使用以前使用的自定义上传逻辑与S3。 picture url looks something like this /profile_picture/:style_:image_hash . 图片网址看起来像这样/profile_picture/:style_:image_hash It works fine with images that are there but with images that are not present paperclip still trying to access image that is not there and the actual link look something like this: http://s3.amazonaws.com/project/profile_pictures/100h_ . 它适用于那里的图像,但是没有回形针的图像仍然试图访问不存在的图像,实际链接看起来像这样: http://s3.amazonaws.com/project/profile_pictures/100h_http://s3.amazonaws.com/project/profile_pictures/100h_

 has_attached_file :picture,
                styles:          { :'53h' => '', :'100h' => '' },
                convert_options: {
                    :'100h' => '-gravity center -thumbnail 165x165^ -extent 165x165',
                    :'53h'  => '-gravity center -thumbnail 45x45^ -extent 45x45'
                },
                path:            'profile_pictures/:style_:filename',
                default_url:     '/images/default-pp-large.jpg'

I am guessing that might be because of style inside the actual filename, but i am not sure, eather way defauly_url is not working and images all are broken, excluding the ones that are actually there. 我猜这可能是因为实际文件名中的样式,但我不确定,eather方式defauly_url不起作用,图像全部被破坏,不包括实际存在的那些。

Can you help please? 你能帮帮忙吗?

In the end i made a monkey pach to paperclip gem. 最后,我做了一个猴子pach到paperclip宝石。 Added this lines to config/initializers/paperclip.rb 将此行添加到config/initializers/paperclip.rb

module Paperclip
  class Attachment
    alias_method :original_url, :url

    def url(style_name = default_style, options = {})
      if @instance.public_send("#{@name.to_s}_file_name").blank?
        'default-pp-large.jpg'
      else
        original_url(style_name, options)
      end
    end
  end
end

i'm wondring how is the ID is not present in the path for the picture, as in this case if 2 differents Pictures with same name it will retrieve the first match as i think, path should be something like: 我想知道如何在图片的路径中不存在ID ,因为在这种情况下如果2个不同的图片具有相同名称它将检索第一个匹配,我认为,路径应该是这样的:

path: 'profile_pictures/:id_:style_:filename'
# OR
path: 'profile_pictures/:id/:style_:filename'

not sure if that should be totally solving the problem but that is a part of it. 不确定这是否应该完全解决问题,但这是其中的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM