我在Google云端部署应用程序时出现问题我收到此错误
的内容不是他们所报道的内容
在当地它工作正常!我已经尝试使用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"]
感谢您的努力。我希望你们能帮助我
答案 0 :(得分:5)
好的,我找到了结果。我刚刚创建了一个initializers/paperclip.rb
文件
require 'paperclip/media_type_spoof_detector'
module Paperclip
class MediaTypeSpoofDetector
def spoofed?
false
end
end
end
现在它对我来说非常合适。
如果使用Rails在App Engine上遇到ImageMagick问题,请参阅此link
答案 1 :(得分: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'
答案 2 :(得分:0)
看起来Google Cloud无法确定上传文件的MIME类型。
您可以将文件扩展名映射到初始值设定项中的类型(application.rb
,production.rb
或创建initializers/paperclip.rb
)
Paperclip.options[:content_type_mappings] = {
:jpg => "image/jpeg",
:png => "image/png",
:gif => "image/gif"
}
但是这种方式不会对图像文件执行欺骗检查。