Paperclip和Phusion Passenger NoHandlerError

时间:2013-03-02 08:28:43

标签: ruby-on-rails-3 rack passenger

我按照本指南通过AJAX拖放文件上传:http://dannemanne.com/posts/drag-n-drop_upload_that_works_with_ror_and_paperclip

使用WebBrick在我的开发环境中一切正常,但如果我部署到PhusionPassenger,那么我得到:

Paperclip::AdapterRegistry::NoHandlerError (No handler found for #<PhusionPassenger::Utils::RewindableInput:0x000000041aef38 @io=#<PhusionPassen...

我在我的控制器中使用它:

before_filter :parse_raw_upload, :only => :bulk_submissions

def bulk_submissions
    ...
    @submission = Submission.create!(url: "", file: @raw_file, description: "Please edit this description", work_type: "other", date_completed: DateTime.now.to_date)  

    ...      
end

private
def parse_raw_upload

  if env['HTTP_X_FILE_UPLOAD'] == 'true'
     @raw_file = env['rack.input']
     @raw_file.class.class_eval { attr_accessor :original_filename, :content_type }
     @raw_file.original_filename = env['HTTP_X_FILE_NAME']
     @raw_file.content_type = env['HTTP_X_MIME_TYPE']
  end
end

查看请求本身所有标头都已设置(X_MIME_TYPE,X_FILE_NAME)等。

有什么想法吗?

提前致谢!

1 个答案:

答案 0 :(得分:3)

您正在尝试的示例要求文件流是StringIO对象,但Passenger正在为您提供PhusionPassenger :: Utils :: RewindableInput对象。

幸运的是,对于这种情况,RewindableInput与StringIO相似,因此Paperclip的StringioAdapter可用于包装上传流。

在parse_raw_upload中的if块内,最后执行:

if @raw_file.class.name == 'PhusionPassenger::Utils::RewindableInput'
  @raw_file = Paperclip::StringioAdapter.new(@raw_file)
end