ruby - 升级 1.8.7 到 1.9.3,回形针 s3 上传不起作用

标签 ruby ruby-on-rails-3 paperclip

当我从 Ruby 1.8.7 迁移到 1.9.3 时,在回形针照片上传方面遇到一个问题。

我们已经配置了 Paperclip,并使用 s3 作为存储。当我使用 1.8.7 运行 Rails 服务器时它工作正常,但它不使用 1.9.3 上传文件(没有任何错误)。

请查看配置和日志。

回形针配置:

has_attached_file :pic,
  :styles => {
    :thumb => "100x100#",
    :one => "118x100#",
    :two => "222x149#",
    :three => "460x345#",
    :popup => "480x360#"
  }, 
  :storage => :s3,
  :s3_credentials => Settings.amazon_s3.to_hash,
  :path => ":attachment/:id/:style/:filename",
  :bucket => Settings.amazon_s3.my_bucket

上传图片时记录

[paperclip] Duplicate URL for photo with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in Photo class
[paperclip] Duplicate URL for photo with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in User class
Command :: identify -format %wx%h '/tmp/stream20120414-20761-hnqjzj.jpg[0]'
Command :: convert '/tmp/stream20120414-20761-hnqjzj.jpg[0]' -resize "x100" -crop "100x100+30+0" +repage '/tmp/stream20120414-20761-hnqjzj20120414-20761-1e0nflx'
Command :: identify -format %wx%h '/tmp/stream20120414-20761-hnqjzj.jpg[0]'
Command :: convert '/tmp/stream20120414-20761-hnqjzj.jpg[0]' -resize "x100" -crop "118x100+21+0" +repage '/tmp/stream20120414-20761-hnqjzj20120414-20761-h7a0ri'
Command :: identify -format %wx%h '/tmp/stream20120414-20761-hnqjzj.jpg[0]'
Command :: convert '/tmp/stream20120414-20761-hnqjzj.jpg[0]' -resize "x149" -crop "222x149+8+0" +repage '/tmp/stream20120414-20761-hnqjzj20120414-20761-10av65c'
Command :: identify -format %wx%h '/tmp/stream20120414-20761-hnqjzj.jpg[0]'
Command :: convert '/tmp/stream20120414-20761-hnqjzj.jpg[0]' -resize "x345" -crop "460x345+46+0" +repage '/tmp/stream20120414-20761-hnqjzj20120414-20761-13ixq6o'
Command :: identify -format %wx%h '/tmp/stream20120414-20761-hnqjzj.jpg[0]'
Command :: convert '/tmp/stream20120414-20761-hnqjzj.jpg[0]' -resize "x360" -crop "480x360+48+0" +repage '/tmp/stream20120414-20761-hnqjzj20120414-20761-g6turu'

分享你对此的想法,我是 Ruby 新手。我错过了一些配置吗?因为它已经在 1.8.7 上运行,所以情况不应该是这样。

更新:

使用 Paperclip 2.7.0、Rails 3.0.11 和 Ruby 1.9.3

最佳答案

在检查执行 model.save! 时抛出的异常后,我找到了解决方案。

基本上,上传的图像文件的内容类型验证失败。这适用于回形针 2.70,但对于 >3.0 版本,我们需要进行如下更改。

#The old contentType setting is commented out    
#validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/pjpeg', 'image/jpg', 'image/png']  

validates_attachment_content_type :photo, :content_type => /image/

现在,图片已成功上传到亚马逊s3服务器上。

引用

Validate Attachment Content Type Paperclip

关于ruby - 升级 1.8.7 到 1.9.3,回形针 s3 上传不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10147038/

相关文章:

ruby-on-rails - rails 如何正确地将模型移动到命名空间

ruby-on-rails - Rails Heroku 服务器回形针 Amazon S3 - AWS::S3::Errors::RequestTimeout

javascript - 来自 form_for 的 Controller 中的 Ajax javascript 响应使用 javascript 呈现为纯文本

ruby-on-rails - 文件上传字段导致 ActionController::InvalidAuthenticityToken 异常

ruby-on-rails - 抓取包含文本 nokogiri xpath 的元素

arrays - 浏览器正在输出对象数组。请帮我摆脱这些

javascript - 单击按钮时执行 Ruby on Rails 代码

ruby-on-rails - 将事件 TCP session 负载均衡到 AWS Aurora RDS

ruby-on-rails - 限制 url 操作返回其他用户记录

ruby - 在 ruby​​ 中散列 url 的最佳方法是什么?