require 'digest/sha1'
class FilesController < ApplicationController
defined?($upr) or before_filter do
# grab the backend in case we forget to set it (or if we're using DRb)
defined?($upr) or ObjectSpace.each_object(Upr::InputWrapper) do |x|
$upr ||= x.backend
end
end
def index
end
def status
tmp = $upr.read(params[:upload_id]).inspect
render :text => "#{Rack::Utils.escape_html(tmp)}\n"
end
def progress
render :update do |page|
status = $upr.read(params[:upload_id]) and
page.upload_progress.update(status.length, status.seen)
end
end
def upload
file = params[:data]
digest = Digest::SHA1.new
if buf = file.read(16384)
begin
digest.update(buf)
end while file.read(16384, buf)
end
size = file.stat.size
File.unlink(file.path)
render :text => "sha1: #{digest.hexdigest}
" \
"size: #{size}
" \
''
end
end