1

我在谷歌云上部署应用程序时遇到问题我收到此错误

包含与报告不符的内容

在本地它工作正常!我已经尝试过使用 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"]

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

4

3 回答 3

5

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

require 'paperclip/media_type_spoof_detector'
module Paperclip
  class MediaTypeSpoofDetector
    def spoofed?
      false
    end
  end
end

现在它非常适合我。

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

于 2016-03-27T23:38:47.657 回答
4

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

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

解决方案:-

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

Paperclip.options[:command_path] = '/usr/bin'
于 2016-08-26T19:25:35.257 回答
0

Google Cloud 似乎无法确定上传文件的 MIME 类型。

您可以将文件扩展名映射到初始化程序(application.rbproduction.rb创建initializers/paperclip.rb)中的类型

Paperclip.options[:content_type_mappings] = {
  :jpg => "image/jpeg",
  :png => "image/png",
  :gif => "image/gif"
}

但是这种方式不会对图像文件执行欺骗检查。

于 2016-03-26T22:07:44.917 回答