Navigation

Subscribe

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!

在一个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
与那些在智能制造新革命背后的人交流

如果您觉得我的博客对您有帮助
可以扫码加入小密圈支持我
碎片的不能成文的文字会在圈内发表

Comments: