[racket] Upload progress bar project

From: Eduardo Bellani (ebellani at gmail.com)
Date: Thu Sep 23 00:21:42 EDT 2010

Hash: SHA1

Hello list.

I am trying to get a HTML upload progress bar to work with Racket's
web server. Here is some of my design notes. If someone would want to
help me, it would be nice since I am trying to come up with a blog
post to showcase the use of racket's web server (and learn a bit).

* A way to keep polling the server and update a field in the page with
  the %. I am thinking about just saving the address to a function in
  a hidden field. I would use that function to return the % based on
  how much of the file is already written to disk.

* A way to know the full size of the file being uploaded.

* A way to calculate how much of a stream of bytes I have written to

* Anything else I don't know yet.

Any tips regarding any of those items would be appreciated.
Here is the basic racket code I have so far:

#lang web-server/insta

; render-upload-page: request -> html-response
; Produces an html-response page of the content of the
; upload page
(define (render-upload-page request)
  (local [(define (response-generator make-url)
            `(html (head (title "Uploader")
                         (script ((src "/uploader.js")) empty))
                    (form ((id "upload-form")
                            ,(make-url insert-upload-handler))
                           (method "post")
                           (enctype "multipart/form-data")
                           (target "upload_target")
                           (onsubmit "startUpload();"))
                          (input ((name "the-file")
                                  (type "file")))
                          (input ((type "submit")))
                          (label ((name "display-%"))
                                 ,(format "~a %" progress))
                          (input ((type "hidden")
                                  (id "progress-so-far")
                                   ,(make-url progress-so-far))))))))

          (define (insert-upload-handler request)
            (match (bindings-assq #"the-file" (request-bindings/raw
              [(? binding:file? the-file)
               (display (binding:file-filename the-file))])
            (render-upload-page (redirect/get)))]
    (send/suspend/dispatch response-generator)))

;; progress-so-far : request -> number
(define (progress-so-far request)

; start: request -> html-response
; Consumes a request, and produces a page that displays
; all of the web content.
(define (start request)
  (render-upload-page request))

(static-files-path "./")


- -- 
Eduardo Bellani

omnia mutantur, nihil interit.
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/


Posted on the users mailing list.