Using Compojure, Hiccup and Ring to upload MULTIPLE files

亡梦爱人 提交于 2019-12-10 14:32:33

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!