-
Notifications
You must be signed in to change notification settings - Fork 525
File Uploads
thescalaguy edited this page Sep 25, 2017
·
11 revisions
Uploading a file to a website requires multipart form handling, which Ring provides with its wrap-multipart-params
middleware.
(use 'ring.middleware.params
'ring.middleware.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.
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 0x65b164dc "/var/folders/td/2r7vtzs95pq79jzjprb_yztc0000gp/T/ring-multipart-6757896657065234625.tmp"],
:size 51
}
},
...
}