Rac*_*494 15 ruby-on-rails paperclip
作为参考,我一直在关注本教程:https://devcenter.heroku.com/articles/paperclip-s3除了我现在在localhost测试中,所以我安装了Figaro gem并将我的S3信息放在application.yml中.
使用Rails v4,Cocaine v0.5.3和Paperclip v4.1.0(不确定是否需要提及任何其他gem版本号).
我有一个名为SubmissionDetails的模型,其new.html.erb中我试图将jpg上传到名为attachment的列.以下是相关的型号代码:
has_attached_file :attachment, styles: {
thumb: '200x200>',
large: '800x800>'
}
validates_attachment_content_type :attachment, content_type: /\Aimage\/.*\Z/
Run Code Online (Sandbox Code Playgroud)
当我尝试上传jpg时,它返回到表单,并显示以下错误消息:
1 error prohibited this submission_detail from being saved:
Attachment translation missing:
en.activerecord.errors.models.submission_detail.attributes.attachment.spoofed_media_type
Run Code Online (Sandbox Code Playgroud)
我理解了一些错误,我的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
Run Code Online (Sandbox Code Playgroud)
Min*_*ohn 42
该消息是通过内容欺骗的验证检查引发的.
对于Paperclip v.4,这会生成一个错误https://github.com/thoughtbot/paperclip/issues/1429
对于Paperclip v.3,它似乎只是抛出一个弃用警告,https://github.com/thoughtbot/paperclip/issues/1423
因此,在使用版本4之前,我会等待Paperclip团队解决此错误.目前我宁愿继续使用版本3.
gem "paperclip", "~> 3.5.3"
Run Code Online (Sandbox Code Playgroud)
或者将其添加到初始化程序以禁用欺骗保护:
require 'paperclip/media_type_spoof_detector'
module Paperclip
class MediaTypeSpoofDetector
def spoofed?
false
end
end
end
Run Code Online (Sandbox Code Playgroud)
请参阅使用Paperclip 4.0 Rails 3无法上传图像
正如最近在该问题的评论中所解释的那样(https://github.com/thoughtbot/paperclip/issues/1429#issuecomment-49821032),添加:
Paperclip.options[:command_path] = '/usr/bin'
Run Code Online (Sandbox Code Playgroud)
to config/initializers/paperclip.rb解决了这个问题.
归档时间: |
|
查看次数: |
14506 次 |
最近记录: |