2013-03-06 51 views
2

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

回答

7

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

1

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

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

这会给你的长度应与上传的数量列表与名称“文件”关联的文件。每个元素将是看起来像这样的列表:

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

更多信息,可以在非常良好的记录reference被发现。