Multipart uploads

Ring's wrap-multipart-params needs Apache commons-fileupload, which doesn't run on Jolt. plumeria.multipart/wrap-multipart-params takes its place with the same request shape: a multipart/form-data request gets :multipart-params (string keys; a repeated name collects into a vector), merged into :params.

It parses with jolt-lang/multipart (Apache-2.0, RFC 7578), which plumeria doesn't pull in itself, so a server that takes no uploads downloads nothing extra. Add it to your app's deps.edn:

jolt-lang/multipart {:git/url "https://github.com/jolt-lang/multipart"
                     :git/tag "v0.1.3" :git/sha "4c9326ab7a88d4551f20c77b4135bfde4d6308a5"}
(require '[plumeria.multipart :refer [wrap-multipart-params]])

(http/run-server
  (wrap-multipart-params
    (fn [req]
      (let [{:keys [filename size tempfile]} (get-in req [:params "upload"])]
        {:status 200 :body (str filename ": " size " bytes")})))
  {:port 18090})

A file arrives as {:filename :content-type :tempfile :size} by default (temp-file-store), or {:filename :content-type :bytes} with {:store (byte-array-store)}. Any Ring store fn of {:filename :content-type :stream} works. A file is held in memory up to :memory-threshold (64 KB) and then written to a temp file as it arrives. Temp files are deleted once the handler has answered, so copy one to keep it (Ring keeps them an hour).

optiondefault
:encodingthe charset for every text field, overriding the part's own
:fallback-encoding"UTF-8"used when neither the part nor an HTML5 _charset_ field names one
:store(temp-file-store)
:max-file-sizebytes per file, checked as they arrive
:max-file-countfiles per request
:max-field-size1 MiBbytes per text field
:max-fields-size4 MiBtext field bytes in all
:max-parts1000parts per request (past it: 400)
:memory-threshold65536bytes of a file kept in memory
:error-handler413the answer when a size or count limit is hit

A malformed body, one missing its closing delimiter, or a boundary over RFC 2046's 70 characters is 400. A charset this runtime doesn't know is skipped for the next choice. The request body is the buffered one (capped by :max-body, 10 MiB) unless the server streams it with :stream-body, and then the parts are read from the socket as they're parsed. The middleware takes both Ring arities.