问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/11163010/using-compojure-hiccup-and-ring-to-upload-multiple-files