新手问题 paperclip 转换图片失败

joinall · 2012年11月07日 · 最后由 seraphim_houwei 回复于 2014年05月13日 · 4388 次阅读

在发帖时,没有格式化 下面的代码,显示不全面,重新编辑再发。

在 update 时报错:

Started PUT "/users/10002" for 192.168.0.241 at 2012-11-07 09:49:48 +0800
Processing by UsersController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"pLn6+LfnNeghxwJwFLd6CkhU9CVgU3Grv1pI3vkmNT4=", "user"=>{"netname"=>"哀思2", "avatar"=>#<ActionDispatch::Http::UploadedFile:0xa14ffb4 @original_filename="Desert.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"Desert.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20121107-1448-4ejq2m>>}, "commit"=>"修改", "id"=>"10002"}
  User Load (1.7ms)  SELECT "USERS".* FROM "USERS" WHERE "USERS"."ID" = :a1 AND ROWNUM <= 1  [["id", 10002]]
Command :: identify -format %wx%h '/tmp/Desert20121107-1448-1uo0vp7.jpg[0]'
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: /tmp/Desert20121107-1448-1uo0vp7.jpg is not recognized by the 'identify' command.>
Command :: identify -format %wx%h '/tmp/Desert20121107-1448-1uo0vp7.jpg[0]'
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: /tmp/Desert20121107-1448-1uo0vp7.jpg is not recognized by the 'identify' command.>
Command :: identify -format %wx%h '/tmp/Desert20121107-1448-1uo0vp7.jpg[0]'
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: /tmp/Desert20121107-1448-1uo0vp7.jpg is not recognized by the 'identify' command.>
Redirected to http://192.168.0.5:3000/users/10002/edit
Completed 302 Found in 303ms (ActiveRecord: 1.7ms)
但是上传 这个图片是正常的其他图片都不行真是好奇怪哦
![](http://l.ruby-china.com/photo/2d7153fdf197582dbcd03fd5a6624952.jpg)

木有人踩我?

你把问题组织下,让别人容易看懂。

确实问题不太清楚,你的 controller 呢,程序呢?

#用户图像-------------------------------------------------------------------------------------------- attr_accessible :avatar has_attached_file :avatar, :styles => { :big => "120x120>", :normal => "48x48#", :small => "16x16>" }, :default_sytle => "normal", :default_url => "/assets/:style_avatar.png", :url => "/uploadfiles/:class/:attachment/:id/:basename/:style.:extension", :path => ":rails_root/public/uploadfiles/:class/:attachment/:id/:basename/:style.:extension"

validates_attachment_content_type :avatar, :content_type =>[ "image/gif",'image/png','image/x-png','image/jpeg','image/pjpeg','image/jpg'], :message => "头像文件需要是图片格式。如:png,jpg.jpeg,gif 等"

def update

@user = current_user if params[:user][:netname] != @user.netname @user.netname = params[:user][:netname] end if params[:user][:avatar] @user.avatar = params[:user][:avatar] end if @user.save
#@user.update_attribute("netname",params[:user][:netname]) flash[:notice] = "用户信息修改成功!" redirect_to user_path(@user) else flash[:notice] = "未知错误,保存失败!" redirect_to edit_user_path(@user) end end

在 update 时报错:


Started PUT "/users/10002" for 192.168.0.7 at 2012-11-11 16:16:35 +0800
Processing by UsersController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"ipIII+Yr0KUqhyWq1XYLVIqIPUTEQC4k/VSWu6lREfQ=", "user"=>{"netname"=>"猎鹰", "avatar"=>#<ActionDispatch::Http::UploadedFile:0xab70a84 @original_filename="20120803160251_72775.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"20120803160251_72775.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20121111-1031-1noi5hp>>}, "commit"=>"修改", "id"=>"10002"}
  User Load (1.7ms)  SELECT "USERS".* FROM "USERS" WHERE "USERS"."ID" = :a1 AND ROWNUM <= 1  [["id", 10002]]
Command :: identify -format %wx%h '/tmp/20120803160251_7277520121111-1031-1yjenhp.jpg[0]'
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: /tmp/20120803160251_7277520121111-1031-1yjenhp.jpg is not recognized by the 'identify' command.>
Command :: identify -format %wx%h '/tmp/20120803160251_7277520121111-1031-1yjenhp.jpg[0]'
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: /tmp/20120803160251_7277520121111-1031-1yjenhp.jpg is not recognized by the 'identify' command.>
Command :: identify -format %wx%h '/tmp/20120803160251_7277520121111-1031-1yjenhp.jpg[0]'
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: /tmp/20120803160251_7277520121111-1031-1yjenhp.jpg is not recognized by the 'identify' command.>
Redirected to http://192.168.0.5:8888/users/10002/edit
Completed 302 Found in 53ms (ActiveRecord: 1.7ms)

joinall@nxbbs-server:/nxbbs/bbs$ which convert /usr/local/bin/convert 在 development.rb 里已经加代码: Paperclip.options[:command_path] = "/usr/local/bin/"

identify 命令结果应该也正常 joinall@nxbbs-server:/nxbbs$ convert logo: kala.jpg joinall@nxbbs-server:/nxbbs$ identify kala.jpg kala.jpg GIF 640x480 640x480+0+0 8-bit sRGB 256c 31.7KB 0.000u 0:00.000

我遇到过,ms 跟有些 gem 冲突了,比如软删除

#11 楼 @Jacob 请问怎么解决的?

。。换掉那个冲突的 gem 啊,实在没办法就做一个 demo,只留必要 gem,看看会不会报错,再慢慢排查

问题已经解决了。 我原来是在 UBUTU11.04 上下载 编译安装。将/usr/local 相关文件全部删除 然后直接 sudo apt-get install imagemagick。安装完成后,正常了。

我也遇到了类似问题,运行$ which convert 得到的路径是/usr/local/bin/convert,但是实际的位置在/usr/bin/convert,把 Paperclip.options[:command_path] 改成/usr/bin/convert/之后,问题解决.

我今天也遇到上面的问题了。后来,在 1 楼 ·那位兄弟那里找到答案了。是因为我的 gem 中,paperclip 与 cocaine 版本不匹配。调整完毕之后,就 ok 了。 cocaine ~> 0.5.3 , paperclip ~> 3.5.2

需要 登录 后方可回复, 如果你还没有账号请 注册新账号