在一个uploader里面同时处理不同文件的截图

我的目的是在一个uploader里面可以同时上传视频和pdf,同时可以截图,视频的截使用gem 'carrierwave-video-thumbnailer'这个gem.

方法如下:

{% highlight ruby %} version :thumb, :if => :thumbable? do
process :efficientconversion => [640, 960], :if => :pdf? process thumbnail: [{format: 'png', quality: 7, size:112, strip: false, square:false, logger: Rails.logger}], :if => :video? def fullfilename forfile pngname forfile, versionname end end

version :large, :if => :thumbable? do process :efficientconversion => [640, 960], :if => :pdf? process thumbnail: [{format: 'png', quality: 7, size:800, strip: false, square:false, logger: Rails.logger}], :if => :video? def fullfilename forfile pngname forfile, versionname end end

def thumbable?(file) pdf?(file) || video?(file) end

protected
def video?(newfile) newfile.contenttype.endwith? '/mp4' end

def pdf?(new_file)
  new_file.content_type.end_with? '/pdf'
end

{% endhighlight %} --END--

钱涌

智能制造师
Email: [email protected]

Hangzhou,China http://qianyong.me