生产中的回形针验证问题

Bil*_*fas 1 ruby google-app-engine ruby-on-rails paperclip paperclip-validation

在Google Cloud上部署应用程序时出现问题

所含内容与所报告的内容不符

在本地工作正常!我已经尝试使用command_path。所以我真的不知道下一步该怎么做...

这是我的模特

has_mongoid_attached_file  :image,
    :styles => { :large => "380x380!" , :medium => "240x240", :small => "120x120!" },
    :storage => :fog,
    :fog_public => true,
    :fog_directory => 'XXXX',
    :path => "images/:id/:style/:basename.:extension",
    :fog_credentials => {  :provider => 'Google',
                           :google_storage_access_key_id => 'XXXXX',
                           :google_storage_secret_access_key => 'XXXXX'}

  validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
Run Code Online (Sandbox Code Playgroud)

感谢你付出的努力。我希望你们能帮助我

Bil*_*fas 5

好吧,我找到了结果。我刚刚创建了一个initializers/paperclip.rb文件

require 'paperclip/media_type_spoof_detector'
module Paperclip
  class MediaTypeSpoofDetector
    def spoofed?
      false
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

现在,它非常适合我。

如果您在使用Rails的App Engine上使用ImageMagick遇到问题,请参见此链接


Nit*_*nke 5

出现该问题的原因是从命令发现的内容类型file返回空字符串。实际上系统无法找到file可执行文件,因此会引发异常并返回空字符串。检查下面的代码

begin
    Paperclip.run("file", "-b --mime :file", :file => '/tmp/RackMultipart20160826-15649-kwvnq2.png').split(/[:;]\s+/).first
rescue Cocaine::CommandLineError
    ""
end
Run Code Online (Sandbox Code Playgroud)

解决方案:-

在初始化文件中添加以下行。

Paperclip.options[:command_path] = '/usr/bin'
Run Code Online (Sandbox Code Playgroud)