heroku paperclip奇怪的错误Paperclip :: Errors :: MissingRequiredValidatorError

时间:2014-02-02 09:12:49

标签: heroku amazon-s3 paperclip

我已经将一个rails应用程序部署到heroku,它工作得很好,直到我更改域名,本地工作正常,现在我开始收到以下错误:Paperclip::Errors::MissingRequiredValidatorError

s3 env变量在heroku上设置,我找不到为什么会出现这个错误, 感谢帮助。

编辑:为了将来的参考,它与heroku无关,一旦重新捆绑,它会在本地抛出相同的错误,如答案所示。

4 个答案:

答案 0 :(得分:52)

使用4.0版(2天前发布)Paperclip需要文件/ mime验证。 只需将以下内容添加到您的模型中:

validates_attachment_content_type :file_name, :content_type => %w(image/jpeg image/jpg image/png)

重要:替换file_name和内容类型,使其适合您的项目。

它在本地工作,因为你可能还没有更新回形针。

答案 1 :(得分:2)

Paperclip(版本4)现在默认是安全的。您必须验证mime类型或文件名,或明确关闭验证。

这是为了防止内容类型欺骗,例如上传一个php文件而不是一个可以公开访问的图像。

推荐的解决方案如下所示:

validates_attachment_content_type :image, :content_type => /\Aimage/

此处的文档:https://github.com/thoughtbot/paperclip#security-validations

注意这不仅仅是一个S3问题。

答案 2 :(得分:2)

或者只是把它全部忽略

do_not_validate_attachment_file_type :image

答案 3 :(得分:0)

试试这个 -

validates_attachment_content_type:file_name,:content_type => / \ Aimage /.* \ Z /