Next: , Previous: , Up: The (www *) Modules   [Contents][Index]


8 (www server-utils form-2-form)

The (www server-utils form-2-form) module provides a procedure to parse a string in ‘multipart/form-data’ format.

Procedure: parse-form type raw-data

Parse raw-data (an integer) bytes from the current input port, as raw form response data of enctype ‘multipart/form-data’ and return an alist. For backward compatibility, raw-data can also be a string.

type is a form:

((multipart . MINOR) [PARAMETER...])

where minor is a downcased symbol (usually mixed), and each parameter is a pair with CAR a downcased symbol and CDR a string. It is an error if one of these parameters is not boundary. For backward compatibility, type may also be a string, the unparsed value of the Content-Type header.

Each element of the alist has the form (name . value), where name is a string and value is either a string or a (four-element) list of:

filename

A string, or #f.

type

A string representing the MIME type of the uploaded file.

raw-headers

A string, including all eol CRLF chars. Incidentally, the type should be (redundantly) visible in one of the headers.

squeeze

A procedure that takes one arg abr (standing for access byte range). If abr is #f, then internal references to the uploaded file’s data are dropped. Otherwise, abr should be a procedure that takes three arguments: a string, a beginning index (integer, inclusive), and an ending index (integer, exclusive).

If there is no type information, value is a simple non-empty string, and no associated information (filename, raw-headers, squeeze) is kept.

parse-form ignores degenerate uploads, that is those parts of raw-data where the part header specifies no filename and the part content-length is zero or unspecified.

why squeeze?

The squeeze interface can help reduce data motion. Consider a common upload scenario: client uploads file(s) for local (server-side) storage.

classic  squeeze
   *        *       0. (current-input-port)
   *        *       1. Guile-WWW string (for parsing purposes)
   *                2. your substring (image/jpeg)
   *        *       3. filesystem

You can achieve the same effect as the “classic” approach by specifying substring (or something like it) as the access-byte-range proc, but you don’t have to. You could, instead, call squeeze with a procedure that writes the byte range directly to the filesystem.


Next: (www server-utils filesystem), Previous: (www server-utils parse-request), Up: The (www *) Modules   [Contents][Index]