如何在hunchentoot中处理多个文件上传?

时间:2013-03-06 14:28:09

标签: web lisp common-lisp hunchentoot

我知道如何使用hunchentoot:post-paremter在hunchentoot中处理单个文件上传,但是当我添加属性multiple时,i。即<input name="file" type="file" multiple="multiple"/>我只为其中一人获得了(hunchentoot:post-paraameter "file")。是否存在(以及什么)接收用户选择的所有文件的机制?

2 个答案:

答案 0 :(得分:7)

Hunchentoot API不直接授予您访问多个上传文件的权限,但您可以使用(hunchentoot:post-parameters *request*)检索所有POST参数列表(包括上传的文件)。这将是一个列表,您可以使用标准的alist技术(例如(remove "file" (hunchentoot:post-parameters hunchentoot:*request*) :test (complement #'equal) :key #'car))获取所有上传文件的列表。

答案 1 :(得分:1)

这是hunchentoot中相当直接的任务。假设您有一个带有<input>name="files"的html multi="true"元素,您可以访问与“files”输入相关联的所有文件,如下所示:

(loop for post-parameter in (hunchentoot:post-parameters*)
            if (equal (car post-parameter) "files")
            collect post-parameter))

这将为您提供一个列表,其长度应与名称“files”相关联的上传文件数相匹配。每个元素都是一个如下所示的列表:

("files" #P"/temporary/file1" "name of file" "file type")

更多信息可以在记录完备的reference中找到。