2013-03-06 46 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被發現。