回形针不支持.doc文件 [英] Paperclip is not supporting .doc file

查看:142
本文介绍了回形针不支持.doc文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在rails 4.0.2中,我使用paperclip gem来上传文件。但它不支持.doc文件。在文件上传字段下面,显示错误消息为有一个扩展名与其内容不匹配。

在模型中,检查内容类型的验证是给出如下:

  validates_attachment_content_type:document,:content_type => ['application / txt','text / plain',
'application / pdf','application / msword',
'application / vnd.openxmlformats-officedocument.wordprocessingml.document',$ b $ 'application / x-rtf','application / x-rtf',' text / rtf',
'text / richtext','application / doc','application / docx','application / x-soffice','application / octet-stream']


现在使用的宝石

  rails(4.0.2,4.0.0,3.2.13,3.2.8,3.0.4,3.0.3)

paperclip(3.5.2,2.3.11,2.3.8)

如何解决这个问题?

  require'paperclip / media_type_spoof_detector 

'
模块Paperclip
class MediaTypeSpoofDetector
def欺骗?
false
end
end
end

centos

 模块Paperclip 
class MediaTypeSpoofDetector
def type_from_file_command
begin
Paperclip。 run(file,-b --mime:file,:file => @ file.path)
rescue Cocaine :: CommandLineError

end
结束
结束
结束

from https://github.com/thoughtbot/paperclip/issues/1429


In rails 4.0.2, I am using paperclip gem to upload files. But it is not supporting .doc file. Below the file upload field, it is showing an error message as "has an extension that does not match its contents"

In model, the validation for checking the content type is given below :

validates_attachment_content_type :document, :content_type => ['application/txt', 'text/plain',
'application/pdf', 'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.oasis.opendocument.text',
'application/x-vnd.oasis.opendocument.text',
'application/rtf', 'application/x-rtf', 'text/rtf', 
'text/richtext', 'application/doc', 'application/docx', 'application/x-soffice', 'application/octet-stream']

Gems which is used right now

rails (4.0.2, 4.0.0, 3.2.13, 3.2.8, 3.0.4, 3.0.3)

paperclip (3.5.2, 2.3.11, 2.3.8)

How can I solve this issue?

解决方案

add this to an initializer to disable spoofing protection:

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

For centOS

 module Paperclip     
 class MediaTypeSpoofDetector      
 def type_from_file_command      
  begin       
    Paperclip.run("file", "-b --mime :file", :file => @file.path)
  rescue Cocaine::CommandLineError
    ""
  end       
end      
end      
end

from https://github.com/thoughtbot/paperclip/issues/1429

这篇关于回形针不支持.doc文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆