7

我正在使用回形针在我的应用程序中上传图像。我的验证是:

 validates_attachment_content_type :image, :content_type => ['image/jpg','image/jpeg', 'image/png', 'image/tiff', 'image/gif']

在 Firefox、chorme 和 IE9 中一切正常。但在IE8中,我得到一个错误 - “照片图像内容类型无效格式!!!

非常感谢任何解决方案或线索。

4

3 回答 3

12

说它需要image/pjpeg内容类型中的额外图像格式,即:content_type => ['image/pjpeg']

下面肯定会有所帮助。

http://blog.joshsoftware.com/2010/11/26/paperclip-validates_attachment_content_type-always-fails-in-ie-6-and-7-for-jepg-and-png-image/

http://blog.siyelo.com/tip-of-the-day-mime-types-for-paperclip-ie8

于 2011-06-27T08:32:03.727 回答
2

你可以试试这个:content_type => /image/

于 2011-06-27T04:01:02.967 回答
1

我想你可能误解了前面的答案。他的建议是在包含“图像”一词时使用正则表达式,而不是在前面添加正斜杠。因此,您修改后的代码将如下所示:

validates_attachment_content_type :image, :content_type => /image/

// 表示您正在对内容类型使用正则表达式,而不是对数组中的每个元素都明确表示。以上将搜索整个 content_type 字符串并匹配图像,或者您可以更严格一些并使用:

validates_attachment_content_type :image, :content_type => /^image/

这意味着字符串必须以单词“image”开头,这是应该的。这也应该可以帮助您通过 IE。

于 2011-06-27T07:29:10.810 回答