<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Jay<div><br></div><div>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...</div><div><br></div><div>Still, I'd like to make some progress, can you advise or give me some pointers on 1) how to&nbsp;read from stdin from my CGI script</div><div><br></div><div>and 2) using the&nbsp;web-server http request parser ?</div><div><br></div><div>Thanks in advance</div><div><br></div><div>E.D</div><div><br></div><div><br><div><div>On 6 Aug 2009, at 17:43, Jay McCarthy wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On Wed, Aug 5, 2009 at 6:09 PM, Emmanuel<br>Delaborde&lt;<a href="mailto:emmanuel.delaborde@cimex.com">emmanuel.delaborde@cimex.com</a>> wrote:<br><blockquote type="cite">Hello<br></blockquote><blockquote type="cite">I am turning a small web application using web/server into a cgi script<br></blockquote><blockquote type="cite">so far so good, but I got stuck when I tried rewriting my file upload<br></blockquote><blockquote type="cite">&nbsp;function<br></blockquote><blockquote type="cite">the form to upload an image was:<br></blockquote><blockquote type="cite">(form ((action ,(make-url add-image))<br></blockquote><blockquote type="cite">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (method "post")<br></blockquote><blockquote type="cite">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (enctype "multipart/form-data"))<br></blockquote><blockquote type="cite">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(input ((type "file")(name "image")))<br></blockquote><blockquote type="cite">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(input ((type "submit"))))<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">and the form handler was:<br></blockquote><blockquote type="cite">(define (add-image request)<br></blockquote><blockquote type="cite">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(match<br></blockquote><blockquote type="cite">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(bindings-assq&nbsp;#"image"&nbsp;(request-bindings/raw request))<br></blockquote><blockquote type="cite">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[(? binding:file? b)<br></blockquote><blockquote type="cite">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (let ([filename (bytes->string/utf-8 (binding:file-filename<br></blockquote><blockquote type="cite">b))])<br></blockquote><blockquote type="cite">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (save-image! (binding:file-content b)&nbsp;filename&nbsp;images-path)<br></blockquote><blockquote type="cite">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (portfolio-insert-image! a-portfolio filename))<br></blockquote><blockquote type="cite">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ])<br></blockquote><blockquote type="cite">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(admin (redirect/get)))<br></blockquote><blockquote type="cite">this worked fine.<br></blockquote><blockquote type="cite">I got the filename with: (binding:file-filename b)<br></blockquote><blockquote type="cite">and the file content with:&nbsp;(binding:file-content b)<br></blockquote><blockquote type="cite">Now I am trying to write the same function&nbsp;using what is provided by<br></blockquote><blockquote type="cite">net/cgi, namely :<br></blockquote><blockquote type="cite">(get-bindings)<br></blockquote><blockquote type="cite">(extract-bindings&nbsp;key?&nbsp;bindings)<br></blockquote><blockquote type="cite">(extract-binding/single&nbsp;key?&nbsp;bindings)<br></blockquote><blockquote type="cite">It seems pretty straightforward when it comes to simple form values, but not<br></blockquote><blockquote type="cite">so with a file upload...<br></blockquote><blockquote type="cite">Can I get both the file name and the file content through the bindings<br></blockquote><blockquote type="cite">functions ?<br></blockquote><blockquote type="cite">Has anybody a simple cgi script dealing with file upload, laying around ?<br></blockquote><blockquote type="cite">Thanks<br></blockquote><blockquote type="cite">E.<br></blockquote><br>You have discovered the reason to get rid of the extract-bindings API.<br><br>I don't know of any work around for CGI scripts. Perhaps the file<br>content is just on stdin after get-bindings... but I really don't<br>know.<br><br>You could try piping stdin to the web-server http request parser and<br>use it's http structs, but from a cgi script, but I haven't tried it<br>before.<br><br>Jay<br><br>-- <br>Jay McCarthy &lt;<a href="mailto:jay@cs.byu.edu">jay@cs.byu.edu</a>><br>Assistant Professor / Brigham Young University<br><a href="http://teammccarthy.org/jay">http://teammccarthy.org/jay</a><br><br>"The glory of God is Intelligence" - D&amp;C 93<br></div></blockquote></div><br><div> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>--</div><div>Emmanuel Delaborde</div><div>Web Technologist</div><div>Cimex<br>53-55 Scrutton Street, London UK, EC2A 4PJ<br>T: +44 (0)20 7324 7780<br>F: +44 (0)20 7324 7781<br><a href="http://www.cimex.com/">http://www.cimex.com</a></div></div></span></div></span> </div><br></div></body></html>
<pre>-----------------------------------------------------------------------------------------------

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@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.