我正在尝试使用paperclip上传.pdf和.doc。
Command :: file -b --mime '/var/folders/86/5tdcyh5171j6twqqkt49tq040000gn/T/d031fe0d3003c25aa6a9d1525403031a20140707-7537-6y9s83.pdf'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/86/5tdcyh5171j6twqqkt49tq040000gn/T/d031fe0d3003c25aa6a9d1525403031a20140707-7537-1ru9fns.pdf[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/86/5tdcyh5171j6twqqkt49tq040000gn/T/d031fe0d3003c25aa6a9d1525403031a20140707-7537-1ru9fns.pdf[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
(0.2ms) begin transaction
Command :: file -b --mime '/var/folders/86/5tdcyh5171j6twqqkt49tq040000gn/T/d031fe0d3003c25aa6a9d1525403031a20140707-7537-1b7261f.pdf'
(0.2ms) rollback transaction
答案 0 :(得分:1)
调整图像大小,:styles => { :medium => "300x300>", :thumb => "345x215#" }
需要imagemagick。安装imagemagick应该可以解决问题。
has_attached_file :media,
:styles => {
:medium => "300x300>",
:thumb => "345x215#",
:pdf_thumbnail => ["", :jpg]
},
:default_url => ActionController::Base.helpers.asset_path('branch-default.jpg')
validates :media, :attachment_content_type => { :content_type => ['image/png', 'image/jpg', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document']}
此外,为pdf上传指定pdf_thumbnail
,因为它会生成缩略图,但我认为此功能需要GhostScript:以下是paperclip github页面的摘录:
如果您正在处理pdf上传或运行测试套件,您还需要安装GhostScript。
其他内容类型缩略图的另一个有用链接: