[plt-scheme] CGI file upload

From: emmanuel.delaborde (emmanuel.delaborde at cimex.com)
Date: Thu Aug 6 12:55:15 EDT 2009

Hi Jay

I thought it would be fairly straightforward, and that maybe I was  
missing something or else the CGI PLT docs had omitted this use case...

Still, I'd like to make some progress, can you advise or give me some  
pointers on 1) how to read from stdin from my CGI script

and 2) using the web-server http request parser ?

Thanks in advance

E.D


On 6 Aug 2009, at 17:43, Jay McCarthy wrote:

> On Wed, Aug 5, 2009 at 6:09 PM, Emmanuel
> Delaborde<emmanuel.delaborde at cimex.com> wrote:
>> 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.
>
> You have discovered the reason to get rid of the extract-bindings API.
>
> I don't know of any work around for CGI scripts. Perhaps the file
> content is just on stdin after get-bindings... but I really don't
> know.
>
> You could try piping stdin to the web-server http request parser and
> use it's http structs, but from a cgi script, but I haven't tried it
> before.
>
> Jay
>
> -- 
> Jay McCarthy <jay at cs.byu.edu>
> Assistant Professor / Brigham Young University
> http://teammccarthy.org/jay
>
> "The glory of God is Intelligence" - D&C 93

--
Emmanuel Delaborde
Web Technologist
Cimex
53-55 Scrutton Street, London UK, EC2A 4PJ
T: +44 (0)20 7324 7780
F: +44 (0)20 7324 7781
http://www.cimex.com


-----------------------------------------------------------------------------------------------

This e-mail (and any attachments) is confidential and may contain 
personal views which are not the views of Cimex Media Ltd and 
any affiliated companies, unless specifically stated. It is intended 
for the use of the individual or group to whom it is addressed. If 
you have received it in error, please delete it from your system, 
do not use, copy or disclose the information in any way nor act in 
reliance on it and please notify postmaster at cimex.com

A company registered in England  Wales. Company Number 03765711
Registered Office : The Olde Bakehouse, 156 Watling Street East, Towcester,
Northants NN12 6DB

This email was scanned by Postini, the leading provider in Managed Email Security.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090806/2fca3ee9/attachment.html>

Posted on the users mailing list.