Ruby on Rails - 回形针错误 [英] Ruby on Rails - Paperclip Error

查看:33
本文介绍了Ruby on Rails - 回形针错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为参考,我一直在关注本教程:https://devcenter.heroku.com/articles/paperclip-s3 除了我现在在本地主机测试中,所以我安装了 Figaro gem 并将我的 S3 信息放在 application.yml 中.

For reference I have been following this tutorial: https://devcenter.heroku.com/articles/paperclip-s3 Except I am in localhost testing right now, so I installed the Figaro gem and placed my S3 info in application.yml.

使用 Rails v4、Cocaine v0.5.3 和 Paperclip v4.1.0(不确定是否需要提及任何其他 gem 版本号).

Using Rails v4, Cocaine v0.5.3, and Paperclip v4.1.0 (unsure if any other gem version numbers need to be mentioned).

我有一个名为 SubmissionDetails 的模型,在其 new.html.erb 中,我尝试将 jpg 上传到名为附件的列.这是相关的模型代码:

I have a model called SubmissionDetails, where in its new.html.erb I am trying to upload a jpg to a column called attachment. Here is the relevant model code:

has_attached_file :attachment, styles: {
thumb: '200x200>',
large: '800x800>'
}

validates_attachment_content_type :attachment, content_type: /\Aimage\/.*\Z/

当我尝试上传 jpg 时,它返回表单并显示以下错误消息:

When I try to upload a jpg, it returns back to the form with the following error message:

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 文件中缺少显示此错误消息的文本,但是那个欺骗的媒体类型部分呢?

I understand some of the error, that text to display this error message is missing from my en.yml file, but what about that spoofed media type part?

这显示在我的服务器控制台中,不确定这是否相关:

This shows up in my server console, not sure if this is relevant:

[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

推荐答案

该消息是由内容欺骗的验证检查引发的.

That message is raised by a validation check for content spoofing.

对于 Paperclip v.4,这会产生一个错误 https://github.com/thoughtbot/paperclip/issues/1429

For Paperclip v.4 this generates a bug https://github.com/thoughtbot/paperclip/issues/1429

虽然对于 Paperclip v.3,它似乎只是抛出了弃用警告,https://github.com/thoughtbot/paperclip/issues/1423

While for Paperclip v.3, it seems it just throws a deprecation warning, https://github.com/thoughtbot/paperclip/issues/1423

所以我会在使用版本 4 之前等待 Paperclip 团队解决这个错误.目前我宁愿继续使用版本 3.

So I'd wait for Paperclip team to solve this bug before using version 4. At the moment I'd rather keep using version 3.

gem "paperclip", "~> 3.5.3"

或将此添加到初始化程序以禁用欺骗保护:

Or add this to an initializer to disable spoofing protection:

require 'paperclip/media_type_spoof_detector'
module Paperclip
  class MediaTypeSpoofDetector
    def spoofed?
      false
    end
  end
end

参见 无法使用 Paperclip 4.0 Rails 3 上传图片

这篇关于Ruby on Rails - 回形针错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆