<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 read from stdin from my CGI script</div><div><br></div><div>and 2) using the 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<<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"> 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"> (method "post")<br></blockquote><blockquote type="cite"> (enctype "multipart/form-data"))<br></blockquote><blockquote type="cite"> (input ((type "file")(name "image")))<br></blockquote><blockquote type="cite"> (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"> (match<br></blockquote><blockquote type="cite"> (bindings-assq #"image" (request-bindings/raw request))<br></blockquote><blockquote type="cite"> [(? binding:file? b)<br></blockquote><blockquote type="cite"> (let ([filename (bytes->string/utf-8 (binding:file-filename<br></blockquote><blockquote type="cite">b))])<br></blockquote><blockquote type="cite"> (save-image! (binding:file-content b) filename images-path)<br></blockquote><blockquote type="cite"> (portfolio-insert-image! a-portfolio filename))<br></blockquote><blockquote type="cite"> ])<br></blockquote><blockquote type="cite"> (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: (binding:file-content b)<br></blockquote><blockquote type="cite">Now I am trying to write the same function 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 key? bindings)<br></blockquote><blockquote type="cite">(extract-binding/single key? 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 <<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&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.