自定义处理器的Paperclip NoHandlerError

时间:2017-02-14 17:27:41

标签: ruby-on-rails-4 paperclip

我正在尝试将上传的视频转换为多种格式但我收到错误

视频模型:

class Video < ActiveRecord::Base
  has_attached_file :video, {
                              preserve_files: true,
                              styles: {
                                  ogg: { :processors => [:ogg_processor] },
                              },
                              url: '/tmp/paperclip/:rails_env/video/:style/:filename',
                              path: ':rails_root/public:url',
                          }

  # paperclip:
  validates :video, attachment_presence: true
  validates_with AttachmentContentTypeValidator, attributes: :video, content_type: /\Avideo\/.*\Z/
  validates_with AttachmentSizeValidator, attributes: :video, less_than: 150.megabytes
end

这种选项的变化也不起作用:

  has_attached_file :video, {
                              preserve_files: true,
                              processors: [:ogg_processor],
                              styles: {
                                  original: {},
                              },
                              url: '/tmp/paperclip/:rails_env/video/:style/:filename',
                              path: ':rails_root/public:url',
                          }

处理器:

# lib/paperclip_processors/ogg_processor.rb
module Paperclip
  class OggProcessor < Processor
    def make
      output = Tempfile.new([File.basename(@file.path), '.ogv'])
      parameters = '--max_size 1280x1280 --output :output :input'
      Paperclip.run('ffmpeg2theora', parameters, output: File.expand_path(file.path), input: File.expand_path(output.path))
      output
    end
  end
end

错误:

Paperclip::AdapterRegistry::NoHandlerError: No handler found for "public/tmp/videos/SampleVideo_720x480_30mb.mkv"
/home/vedant/.gem/ruby/2.2.4/gems/paperclip-4.3.7/lib/paperclip/io_adapters/registry.rb:19:in `handler_for'
/home/vedant/.gem/ruby/2.2.4/gems/paperclip-4.3.7/lib/paperclip/io_adapters/registry.rb:29:in `for'
/home/vedant/.gem/ruby/2.2.4/gems/paperclip-4.3.7/lib/paperclip/attachment.rb:98:in `assign'
/home/vedant/.gem/ruby/2.2.4/gems/paperclip-4.3.7/lib/paperclip/has_attached_file.rb:66:in `block in define_setter'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/attribute_assignment.rb:54:in `public_send'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/attribute_assignment.rb:54:in `_assign_attribute'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/attribute_assignment.rb:35:in `each'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/attribute_assignment.rb:35:in `assign_attributes'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/core.rb:566:in `init_attributes'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/core.rb:281:in `initialize'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/inheritance.rb:61:in `new'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/inheritance.rb:61:in `new'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/persistence.rb:50:in `create!'
/home/vedant/web/voggle/lib/tasks/dummy.rake:47:in `block (3 levels) in <top (required)>'
/home/vedant/web/voggle/lib/tasks/dummy.rake:46:in `each'
/home/vedant/web/voggle/lib/tasks/dummy.rake:46:in `block (2 levels) in <top (required)>'
/home/vedant/.gem/ruby/2.2.4/gems/airbrake-5.5.0/lib/airbrake/rake/task_ext.rb:19:in `execute'
/home/vedant/.gem/ruby/2.2.4/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => dummy:videos
(See full trace by running task with --trace)

1 个答案:

答案 0 :(得分:0)

好吧,这是一个非常愚蠢的错误。

我发送的是String而不是File个对象。我刚做File.new(video_file)并且它有效。