chickadee » schematra » read-current-multipart-form-data

read-current-multipart-form-data #!optional max-lengthprocedure

Decodes the current multipart request body using the body captured by body-parser-middleware. It opens a fresh request-body-port and calls multipart-form-data-decode, so it does not try to re-read the original request port.

Do not call read-multipart-form-data from the multipart-form-data egg after installing body-parser-middleware; the original request port has already been consumed.

(import schematra.body-parser multipart-form-data)

(with-schematra-app app
  (lambda ()
    (use-middleware! (body-parser-middleware))

    (post "/upload"
          (let* ((parts  (read-current-multipart-form-data))
                 (title  (alist-ref 'title parts))
                 (upload (alist-ref 'file parts)))
            (when (multipart-file? upload)
              (let ((filename (multipart-file-filename upload))
                    (port     (multipart-file-port upload)))
                (save-upload! filename port)))
            (string-append "Uploaded: " title)))))