3 class FilesController < ApplicationController
4 # used by jQuery streaming upload progress
9 # based on Ry Dahl's streaming AJAX pull:
10 # http://rubyforge.org/pipermail/mongrel-users/2007-July/003747.html
18 # used by mup-compatible upload progress
20 tmp = $upr.read(params[:upload_id]).inspect
21 render :text => "#{Rack::Utils.escape_html(tmp)}\n"
24 # used by mup-compatible upload progress
26 render :update do |page|
27 status = $upr.read(params[:upload_id]) and
28 page.upload_progress.update(status.length, status.seen)
32 # used by mup-compatible upload progress
34 size, hexdigest = _read_sha1_size
35 render :text => "sha1: #{hexdigest}<br />" \
36 "size: #{size}<br />" \
37 '<script type="text/javascript">' \
38 'window.parent.UploadProgress.finish();</script>'
44 file = params[:data] or return [ -1, :unknown ]
45 File.unlink(file.path) if file.respond_to?(:path)
46 digest = Digest::SHA1.new
47 if buf = file.read(16384)
50 end while file.read(16384, buf)
52 [ file.size, digest.hexdigest ]
57 size, hexdigest = _read_sha1_size
58 msg = "Successfully upload file (size: #{size}, sha1: #{hexdigest})"
60 redirect_to :action => params[:action]