[Chicken-users] reading file from post request

2014-08-09 Thread Nathaniel Rudavsky-Brody

Hello,

In an Awful web app, I'm trying to read an image posted as raw data to 
the server, since it seems multipart/form-data isn't supported. (Is 
that right?) But I get the feeling I'm missing something regarding 
ports and requests...


I *think* my basic question is, how do I know the request is finished? 
But more than that, is there a better way to be going this?


I've got something like:

 (with-output-to-file media/image.jpg   
   
  (lambda ()  

(port-map write-byte
			 (lambda () 
(read-byte (request-port (current-request)))


; never gets here
Success


With JSON objects this wasn't a problem, using Medea: 

(read-json (request-port (current-request)) 
consume-trailing-whitespace: #f)



Thanks a lot for any help,

Nathaniel
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] reading file from post request

2014-08-09 Thread Peter Bex
On Sat, Aug 09, 2014 at 05:40:31PM +0002, Nathaniel Rudavsky-Brody wrote:
 Hello,
 
 In an Awful web app, I'm trying to read an image posted as raw data to 
 the server, since it seems multipart/form-data isn't supported. (Is 
 that right?) But I get the feeling I'm missing something regarding 
 ports and requests...
 
 I *think* my basic question is, how do I know the request is finished? 

It depends a bit on the type of request; if it's using chunked encoding,
the request-port you get is delimited, so you can just read until EOF.
Otherwise, you'll have to check the request's content-length header.

The nice bit about this is that if the client uses chunked encoding,
there will be no content-length header.  So either you read until
content-length is hit, or until EOF.

 With JSON objects this wasn't a problem, using Medea: 
 
 (read-json (request-port (current-request)) 
 consume-trailing-whitespace: #f)

The reason you didn't run into problems here is that JSON objects
are self-delimited.  They always look like {...} or [...].  However,
if some library accidentally put some trailing whitespace in there you
would probably run into trouble upon reading the next request, when the
connection is keepalive.

Cheers,
Peter
-- 
http://www.more-magic.net

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users