【问题标题】:Paperclip is working for images but not for PDF filesPaperclip 适用于图像,但不适用于 PDF 文件
【发布时间】:2012-02-07 06:31:56
【问题描述】:

我有一个使用 Paperclip 的 Rails 3.1 应用程序。它在本地工作得很好,但在服务器上我似乎无法让 PDF 上传工作。 PNG 和 JPG 图片完美运行。

尝试保存带有 PDF 附件的记录时,我收到以下错误:

Avatar /tmp/stream20120110-10803-1whykjx-0.pdf is not recognized by the 'identify' command.
Avatar /tmp/stream20120110-10803-1whykjx-0.pdf is not recognized by the 'identify' command.

我检查了显示以下内容的 Apache 日志:

sh: gs: not found
identify: Postscript delegate failed `/tmp/stream20120110-5508-or6g2v-0.pdf': No such file or directory @ pdf.c/ReadPDFImage/634.
sh: gs: not found
identify: Postscript delegate failed `/tmp/stream20120110-5508-or6g2v-0.pdf': No such file or directory @ pdf.c/ReadPDFImage/634.
cache: [POST /courses] invalidate, pass
sh: gs: not found
identify: Postscript delegate failed `/tmp/stream20120110-5508-vgyyz8-0.pdf': No such file or directory @ pdf.c/ReadPDFImage/634.
sh: gs: not found
identify: Postscript delegate failed `/tmp/stream20120110-5508-vgyyz8-0.pdf': No such file or directory @ pdf.c/ReadPDFImage/634.
cache: [POST /courses] invalidate, pass

我无法确定问题出在哪里,Imagemagick 已安装在服务器(运行 Ubuntu)上,并且图像文件可以正常工作。我看不到任何文件大小限制的参考,所以我不认为是这样。

感谢任何帮助!

编辑:

只是为了确认我已经查看了“识别”无法识别等问题,并尝试将以下内容添加到我的 production.rb 环境文件中:

Paperclip.options[:command_path] = "/usr/bin/identify"

但这没什么区别。

【问题讨论】:

  • 看起来它正在尝试运行 ghostscript 作为该过程的一部分,也许是缩略图。也许是一个自定义类来跳过这一步?我将从回形针代码开始,看看默认的 PDF 处理程序是做什么的。也可以是一个配置。
  • 知道了,我不需要缩略图或类似的东西,所以我从回形针代码中删除了它。谢谢!

标签: ruby-on-rails upload paperclip


【解决方案1】:

对于任何感兴趣的人,我采取了以下步骤来纠正这个问题。请注意,我不需要图像大小调整、缩略图等。

我更改了这样的模型代码:

class User < ActiveRecord::Base
  has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end

到这里:

class User < ActiveRecord::Base
  has_attached_file :avatar
end

【讨论】:

    猜你喜欢
    • 2012-07-01
    • 2012-10-15
    • 1970-01-01
    • 1970-01-01
    • 2016-02-23
    • 1970-01-01
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多