Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Compojure, Hiccup and Ring to upload MULTIPLE files

Tags:

clojure

ring

This is really a rip off of Using Compojure, Hiccup and Ring to upload a file

If there is a multiple tag:

<form action="/file" method="post" enctype="multipart/form-data">
  <input name="file" type="file" size="20" multiple/>
<input type="submit" name="submit" value="submit" />

How would one go about getting the values of all the files using ring?

like image 885
zcaudate Avatar asked Jun 22 '12 19:06

zcaudate


1 Answers

I created a test project and checked what sort of data the request map contains when arriving to the back-end when submitting multiple files. Below is a part of the request map:

{:multipart-params {"submit" submit,
                    "file" [{:size 439,
                             :tempfile #<File /tmp/ring-multipart-5216436296043515206.tmp>,
                             :content-type application/javascript,
                             :filename bar.js}
                            {:size 24,
                             :tempfile #<File /tmp/ring-multipart-3573753728611312574.tmp>,
                             :content-type application/octet-stream,
                             :filename foo.md}], ...}

Seems that (get-in request [:multipart-params "file"]) would give you a vector of the uploaded files, containing information on what their original file names and types were and where they are temporarily stored. According to Ring's documentation the files will be stored for one hour.

like image 189
ponzao Avatar answered Sep 21 '22 12:09

ponzao