You are looking at historical revision 2259 of this page. It may differ significantly from its current revision.
Introduction
The spiffy-form-posts egg extends the Spiffy web server to include support for parsing of multipart/form-data form posts. It includes some data structures and utilties for representing and inspecting form posts.
License
spiffy-form-posts is in the Public Domain and may be reproduced or copied without permission.
Authors
Moe Aboulkheir
Requirements
Examples
Canonical Usage
(use spiffy spiffy-form-posts) (http:add-resource "/form-post" (lambda (req args) (let* ((form-fields (request->form-field-alist req)) (file-input (alist-ref "file" form-fields string=?)) (response (string-append "You uploaded a file called " (form-field:file-name file-input) " which has a content type of " (form-field:content-type file-input) ". The contents of this file are: " (form-field:body file-input)))) ; ... write the response ... )))
Conversion
request->form-field-list
[procedure] (request->form-field-list req)
Returns a list of form-field records, one for each form field that has a part in the body of the Spiffy request req, in the same order as the parts appear in the posted document.
request->form-field-alist
[procedure] (request->form-field-alist req)
Same as request->form-field-list, but returns an association list which maps (string) names of form post parts to form-field records.
form-field-list->form-field-alist
[procedure] (form-field-list->form-field-alist req)
Converts a form field list (as returned by request->form-field-list) into the same format as the return value of request->form-field-alist.
Predicates
form-field?
[procedure] (form-field? anything)
Returns a boolean indicating whether anything is of the form-field record type.
form-field:file-field?
[procedure] (form-field:file-field? form-field)
Returns a boolean indicating whether form-field is a file field/file input (i.e. does its content-disposition header have a filename parameter?).
Selectors
form-field:name
[procedure] (form-field:name form-field)
Returns the string name of form-field (i.e. the value of the name parameter of the corresponding content-disposition header).
form-field:body
[procedure] (form-field:body form-field)
Returns the string body of form-field (i.e. the body of its part in the form post).
form-field:content-type
[procedure] (form-field:content-type form-field)
Returns the string content type of form-field (i.e. the value of the content-type header for its part in the form post).
form-field:file-name
[procedure] (form-field:file-name form-field)
Returns the string name of the file whose content is the body of form-field. Will return #f if form-field is not a file field (i.e. if (form-field-file-field? form-field) does not evaluate to #t).