如何使用Rails中的Paperclip gem上传Outlook文件(.msg扩展名)

时间:2014-08-15 14:44:43

标签: ruby-on-rails ruby outlook paperclip-validation

我需要能够将电子邮件附加到模型,特定的.eml和.msg文件

Paperclip现在要求验证使用它上传的文件类型。

我的代码中存在这些验证的部分在这里:

validates_attachment_content_type :supporting_document,
:content_type => ['application/pdf', 'application/vnd.ms-excel',
                  'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
                  'image/jpeg', 'image/jpg', 'image/png',
                  'application/vnd.ms-excel.sheet.macroEnabled.12', 'application/msword',
                  'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
                  'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',EML_MIMETYPE],
:message => 'incorrect file type.'

最后一部分EML_MIMETYPE用于.eml文件,并定义为常量:

EML_MIMETYPE = 'message/rfc822'

我通过在测试.eml文件的终端中使用file命令为.eml文件找到了正确的MIME TYPE:

$ file -b --mime-type ~/Desktop/noname.eml

但是,当我在示例.msg文件上执行此操作时,它会返回看起来像已损坏的MIME类型的内容

$ file -b --mime-type ~/Desktop/testemail.msg
>application/CDFV2-corrupt

在线查看,此链接http://social.msdn.microsoft.com/Forums/en-US/8efe300d-c917-4be7-a0f3-e620e029842b/what-mime-type-can-i-use-for-msg-files?forum=netfxnetcom建议使用MIME类型" application / vnd.ms-outlook" ,但我没有运气。

有什么建议吗?我正在运行linux xubuntu 14.04,该应用程序正在使用Rails 3.2.18和ruby 1.9.3p392

1 个答案:

答案 0 :(得分:0)

为什么不默认使用application / octet-stream?