【问题标题】:How to upload an Outlook file ( .msg extension) using the Paperclip gem in Rails如何使用 Rails 中的 Paperclip gem 上传 Outlook 文件(扩展名为 .msg)
【发布时间】:2014-10-09 07:34:09
【问题描述】:

我需要能够将电子邮件附加到模型,特别是 .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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 不知道我会怎么做...你能发布一个我会使用的代码示例吗?
    • 我对Ruby几乎一无所知,你现在如何设置内容类型?
    • 你找到解决办法了吗?
    猜你喜欢
    • 2014-07-17
    • 1970-01-01
    • 2012-03-10
    • 1970-01-01
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    相关资源
    最近更新 更多