def ajax_upload
      filename = @options[:filename]
      type = @options[:mimetype] || mimetype(filename)
      file = @options[:tempfile] || "/tmp/upload-#{filename}"

      # Pass stream (typically request.body) to read chunks
      if @options[:stream]
        File.open(file, 'w') do |f|
          f.binmode
          while buffer = @options[:stream].read(51200)
            f << buffer
          end
        end
      end

      {:filename => filename, :tempfile => File.new(file), :type => type}
    end
def ajax_upload
      filename = @options[:filename]
      type = @options[:mimetype] || mimetype(filename)
      file = @options[:tempfile] || "/tmp/upload-#{filename}"

      # Pass stream (typically request.body) to read chunks
      if @options[:stream]
        File.open(file, 'w') do |f|
          f.binmode
          while buffer = @options[:stream].read(51200)
            f << buffer
          end
        end
      end

      {:filename => filename, :tempfile => File.new(file), :type => type}
    end
Ajax upload