ruby-on-rails – Ruby on Rails – 纸夹错误
作为参考,我一直在跟随本教程:
https://devcenter.heroku.com/articles/paperclip-s3除了我现在在本地主机测试,所以我安装了费加罗宝石,并将我的S3信息放在application.yml.
使用Rails v4,Cocaine v0.5.3和Paperclip v4.1.0(不确定是否有其他宝石版本号需要提及). 我有一个名为SubmissionDetails的模型,在其new.html.erb中,我试图将jpg上传到一个名为附件的列.以下是相关型号代码: has_attached_file :attachment,styles: { thumb: '200x200>',large: '800x800>' } validates_attachment_content_type :attachment,content_type: /Aimage/.*Z/ 当我尝试上传一个JPG,它返回到表单与以下错误信息: 1 error prohibited this submission_detail from being saved: Attachment translation missing: en.activerecord.errors.models.submission_detail.attributes.attachment.spoofed_media_type 我了解一些错误,从我的en.yml文件中缺少显示此错误消息的文本,但是该欺骗的媒体类型部分呢? 这显示在我的服务器控制台中,不知道这是否相关: [paperclip] Content Type Spoof: Filename header.jpg (["image/jpeg"]),content type discovered from file command: . See documentation to allow this combination. (0.0ms) rollback transaction 解决方法
该消息由对内容欺骗的验证检查引发.
对于Paperclip v.4,它会产生一个错误https://github.com/thoughtbot/paperclip/issues/1429 而对于Paperclip v.3,似乎只是抛出了一个弃权警告https://github.com/thoughtbot/paperclip/issues/1423 所以我等待Paperclip团队在使用版本4之前解决这个bug.目前我宁愿继续使用版本3. gem "paperclip","~> 3.5.3" 或者将其添加到初始化器以禁用欺骗保护: 配置/初始化/ paperclip_media_type_spoof_detector_override.rb require 'paperclip/media_type_spoof_detector' module Paperclip class MediaTypeSpoofDetector def spoofed? false end end end 见Can’t upload image using Paperclip 4.0 Rails 3 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |