[plt-scheme] CGI file upload

From: Emmanuel Delaborde (emmanuel.delaborde at cimex.com)
Date: Wed Aug 5 20:09:34 EDT 2009

Hello

I am turning a small web application using web/server into a cgi script
so far so good, but I got stuck when I tried rewriting my file  
upload  function

the form to upload an image was:

(form ((action ,(make-url add-image))
                            (method "post")
                            (enctype "multipart/form-data"))
                           (input ((type "file")(name "image")))
                           (input ((type "submit"))))


and the form handler was:

(define (add-image request)
             (match
                 (bindings-assq #"image" (request-bindings/raw request))
               [(? binding:file? b)
                (let ([filename (bytes->string/utf-8 (binding:file- 
filename b))])
                  (save-image! (binding:file-content b) filename  
images-path)
                  (portfolio-insert-image! a-portfolio filename))
                ])
             (admin (redirect/get)))

this worked fine.
I got the filename with: (binding:file-filename b)
and the file content with: (binding:file-content b)

Now I am trying to write the same function using what is provided by  
net/cgi, namely :

(get-bindings)
(extract-bindings key? bindings)
(extract-binding/single key? bindings)

It seems pretty straightforward when it comes to simple form values,  
but not so with a file upload...
Can I get both the file name and the file content through the  
bindings functions ?
Has anybody a simple cgi script dealing with file upload, laying  
around ?

Thanks

E.








-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090806/8f1048e5/attachment.html>

Posted on the users mailing list.