【问题标题】:Paperclip photo upload fails in IE8回形针照片上传在 IE8 中失败
【发布时间】:2011-06-27 03:52:45
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: ruby-on-rails internet-explorer-8 paperclip-validation


    【解决方案1】:

    说它在内容类型中需要额外的图像格式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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 嗨 Codeglot,正如你所说,我这样做了:validates_attachment_content_type :image, :content_type => ['/image/jpg','/image/jpeg', '/image/png', '/image/tiff', '/image/gif']。但是现在照片上传在任何浏览器中都不起作用。我错过了什么吗?
      【解决方案3】:

      我想你可能误解了前面的答案。他的建议是在包含单词“图像”时使用正则表达式,而不是在前面添加正斜杠。所以你修改后的代码应该是这样的:

      validates_attachment_content_type :image, :content_type => /image/
      

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

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

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

      【讨论】:

      • 感谢您的提示。在这里非常有用:)
      猜你喜欢
      • 2013-11-09
      • 2011-01-03
      • 2011-01-08
      • 1970-01-01
      • 2013-05-06
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      • 2013-02-28
      相关资源
      最近更新 更多