[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

From: Nathaniel Rudavsky-Brody
Subject: Re: [Chicken-users] reading file from post request
Date: Tue, 12 Aug 2014 12:36:23 +0002

Thanks a lot, that works perfectly.

By the way, is there a "best" way to parse multipart-form data? I tried with a horrible mix of read-line and read-char, and lost count pretty quickly.



On Sam, Aug 9, 2014 at 9:21 , Peter Bex <address@hidden> wrote:
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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]