【问题标题】:uninitialized constant Paperclip::Error with paperclip-ffmpeg未初始化的常量 Paperclip::Error with paperclip-ffmpeg
【发布时间】:2014-05-07 08:50:09
【问题描述】:

我正在使用 Paperclip 和 paperclip-ffmpeg 来处理上传。下面是我的代码

类资产<:base>

 belongs_to :profile  
 has_attached_file :photo, :styles => {
      :mobile => {:geometry => "400x300", :format => 'mp4', :streaming => true}
  }, :processors => [:ffmpeg]


 validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png',  'image/gif', 'application/msword', 'application/pdf', 'video/x-flv']

结束

当我上传图像或视频文件时,它工作正常。但是当我上传 PDF 或 doc 时

文件,出现此错误。

       "uninitialized constant Paperclip::Error" 

有什么帮助吗??

或者如果上传文件是 PDF 或 Doc,我该如何放置条件验证。那我可以跳过这个

下面的代码。因为这是文件类型为 PDF 或 Doc 时出错的原因。

        ":styles => {
      :mobile => {:geometry => "400x300", :format => 'mp4', :streaming => true}
  }, :processors => [:ffmpeg]" 

谢谢

【问题讨论】:

  • 你有这方面的日志吗?
  • Command :: ffmpeg -i '/tmp/stream20140507-5233-1qu3jll.doc' -y '/tmp/stream20140507-5233-1qu3jll20140507-5233-1nbuoe4.mp4' Completed 500 Internal Server Error in 211.7ms NameError(未初始化常量Paperclip::Error):app/controllers/job_seeker_controller.rb:126:in new' app/controllers/job_seeker_controller.rb:126:in new_resume'
  • @RichPeck 以上对你有用吗?
  • @RichPeck 我怎样才能把 lambda 条件用这个? has_attached_file :photo, :styles => { :mobile => {:geometry => "400x300", :format => 'mp4', :streaming => true} }, :processors => [:ffmpeg] #用于跳过 ffmpeg带有 doc 文件的处理器
  • 嗯嗯嗯嗯嗯,知道这件事的人是@kirti thorat。我会在 LinkedIn 上给她发一条消息,看看她是否知道 Paperclip::Error 是什么

标签: ruby-on-rails pdf ffmpeg paperclip paperclip-validation


【解决方案1】:

我已在 LinkedIn 上为您询问 Kirti Thorat - 她可能比我更适合处理 Paperclip::Error 问题


或者如果上传文件是 PDF 或 Doc,我该如何放置条件验证

在格式化has_attached_file 方法以使用lambdahere's what we've done before 方面:

has_attached_file :attachment,
     styles:        lambda { |a| a.instance.is_image? ? {:small => "x200>", :medium => "x300>", :large => "x400>"}  : {:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10}, :medium => { :geometry => "300x300#", :format => 'jpg', :time => 10}}},
     :processors => lambda { |a| a.is_video? ? [ :ffmpeg ] : [ :thumbnail ] }

def is_video?
 attachment.instance.attachment_content_type =~ %r(video)
end

def is_image?
 attachment.instance.attachment_content_type =~ %r(image)
end

这是相对较旧的代码,所以为了让您保持更新,Paperclip 4.0 发布了一个新的媒体欺骗功能,它基本上直接检查您的文件(而不是扩展名)的内容类型。 Kirti对此了解很多,所以最好等待她的回答

如果你愿意,我可以尝试一下

【讨论】:

    猜你喜欢
    • 2012-11-25
    • 2017-05-26
    • 1970-01-01
    • 2018-03-08
    • 2016-09-08
    • 1970-01-01
    • 2013-11-13
    • 2011-09-06
    • 1970-01-01
    相关资源
    最近更新 更多