1

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

资产类 < ActiveRecord::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]" 

谢谢

4

1 回答 1

1

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


或者如果上传文件是 PDF 或 Doc,我如何进行条件验证

在格式化您的has_attached_file方法以使用 a方面lambda这是我们之前所做的

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对此了解很多,所以最好等待她的回答

如果你想要我,我可以尝试一下

于 2014-05-07T09:14:41.860 回答