-
Notifications
You must be signed in to change notification settings - Fork 524
File Uploads
James Reeves edited this page Sep 26, 2017
·
11 revisions
Uploading a file to a website requires multipart form handling, which Ring provides with its wrap-multipart-params
middleware.
(require '[ring.middleware.params :refer [wrap-params]]
'[ring.middleware.multipart-params :refer [wrap-multipart-params]])
(def app
(-> your-handler
wrap-params
wrap-multipart-params))
By default, uploads are stored in temporary files that are deleted an hour after being uploaded. This is handled by ring.middleware.multipart-params.temp-file/temp-file-store function.
For example,
curl -XPOST "http://localhost:3000" -F [email protected]
This adds a file
key to the :params
map of the request where :tempfile
is a java.io.File
object that contains the uploaded data. You can use this to perform any further processing you want.
{...
:params
{"file" {:filename "words.txt"
:content-type "text/plain"
:tempfile #object[java.io.File ...]
:size 51}}
...}