将 1.8.7 升级到 1.9.3,回形针 s3 上传不起作用 [英] Upgrading 1.8.7 to 1.9.3, paperclip s3 upload not working

查看:49
本文介绍了将 1.8.7 升级到 1.9.3,回形针 s3 上传不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从 Ruby 1.8.7 迁移到 1.9.3 时,遇到了一个关于 Paperclip 照片上传的问题.

While i am migrating from Ruby 1.8.7 to 1.9.3, facing one issue on Paperclip photo upload.

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

We have Paperclip configured, with s3 as a store. It works fine when i run rails server using 1.8.7, but its not uploading the file (without any error) with 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 上工作,所以不应该是这样.

Share your ideas on this, i am new to Ruby. do i missed some configuration? Because its already working on 1.8.7, that should not be the case.

更新:

使用 Paperclip 2.7.0、Rails 3.0.11 和 Ruby 1.9.3

Using Paperclip 2.7.0, Rails 3.0.11 and Ruby 1.9.3

推荐答案

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

I found the solution after i checked the exception thrown while doing model.save!.

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

Basically, the content type validation was failing for the uploaded image file. This was working with paperclip 2.70, but for >3.0 version we need to change as following.

#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/

到此,图片已经成功上传到amazon s3服务器.

So now, image has been uploaded successfully on amazon s3 server.

参考

验证附件内容类型回形针

这篇关于将 1.8.7 升级到 1.9.3,回形针 s3 上传不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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