The Hunchentoot API does not directly give you access to multiple uploaded files, but you can use (hunchentoot:post-parameters *request*)
to retrieve the list of all POST parameters (which includes the uploaded files). This will be an alist, and you can get a list of all uploaded files using standard alist techniques (e.g. (remove "file" (hunchentoot:post-parameters hunchentoot:*request*) :test (complement #'equal) :key #'car)
).
How to handle multiple file upload in hunchentoot?
-
18-03-2022 - |
Question
I know how to handle a single file upload in hunchentoot using hunchentoot:post-parameter
, but when I add a property multiple
, i.e., <input name="file" type="file" multiple="multiple"/>
. I got (hunchentoot:post-parameter "file")
only for one of them. Is there (and what is ) the mechanism for receiving all files, chosen by user?
Solution
OTHER TIPS
This is a rather straight-forward task in hunchentoot. Assuming you have a html <input>
element with name="files"
and multi="true"
, you could access all the files associated with the the "files" input like this:
(loop for post-parameter in (hunchentoot:post-parameters*)
if (equal (car post-parameter) "files")
collect post-parameter))
This will give you a list whose length should match the number of uploaded files associated with the name "files". Each of the elements will be a list that looks like this:
("files" #P"/temporary/file1" "name of file" "file type")
More information can be found in the very well-documented reference.