Question of uploading large file using carrierwave, uploadify and nginx upload module

Hey ROR users,
I have a small experimental web app which is for uploading files. The
web app uses carrierwave, uploadify. It works fine on small size
files. However, it can not handle large size files (>1G) efficiently.
Then I decided using nginx upload module, it worked well on small size
files after modification of codes,. But It fails on uploading large
files (>1G) because of http error 499 (client closed connection before
nginx response). The problem here is that, when the uploadify script
finishes sending file to nginx upload module, the uploadify javascript
expects a quick response because the uploadify has finished uploading
files and onAllComplete function will have to execute, however, the
saving object takes much longer time and return late, and the
javascript terminate prematurely, and issues a IO error. In fact, the
file is successfully uploaded and placed in the correct place.


  def create
    @attachment = => params[:fast_asset])
    if # the line takes long time to finish
      render :nothing => true
      render 'new'

attachment model

class Attachment < ActiveRecord::Base
  attr_accessible :file, :fast_asset
  mount_uploader :file, FileUploader

  def fast_asset=(file)
    if file && file.respond_to?('[]')
      tmp_upload_dir = "#{file['filepath']}_1"
      tmp_file_path = "#{tmp_upload_dir}/#{file['@original_name']}"
      FileUtils.mkdir_p(tmp_upload_dir)['filepath'], tmp_file_path)
      self.file =


the new uploading form uses the uploadify basic example javascript
code. (


= javascript_include_tag 'swfobject.js', 'jquery.uploadify.v2.1.4.min.js'
  $(document).ready(function() {
      buttonText: 'Select files',
      uploader: '/uploadify/uploadify.swf',
      cancelImg: '/uploadify/cancel.png',
      multi: true,
      auto: false,
      script: '/files/fast_upload',
      onComplete: function(event, queueID, fileObj, response, data) {
        var dat = eval('(' + response + ')');
      onAllComplete: function(event, data) {
        alert(data.filesUploaded + ' files uploaded successfully!\nThe
average speed is ' + data.speed);
        window.location = '#{root_path}';
= form_for @attachment, :html => { :multipart => true } do |f|
    =f.label :file
    =f.file_field :file
    =f.submit "Upload"

How should I fix the problem? Thanks in advance,