在一个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--

智造师小密圈

Meet some of the people behind the new manufacturing revolution
与那些在智能制造新革命背后的人交流

于仁颇黎


Email: qianyong{@}qianyong.me

Hangzhou,China http://qianyong.me