【问题标题】:How to handle multiple file upload in hunchentoot?如何处理hunchentoot中的多个文件上传?
【发布时间】:2013-03-06 14:28:09
【问题描述】:

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

【问题讨论】:

    标签: web lisp common-lisp hunchentoot


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      这在 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”相关联的上传文件的数量相匹配。每个元素都是一个如下所示的列表:

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

      更多信息可以在文档齐全的reference中找到。

      【讨论】:

        猜你喜欢
        • 2015-07-02
        • 1970-01-01
        • 2011-01-15
        • 1970-01-01
        • 2013-07-17
        • 1970-01-01
        • 2017-11-20
        • 2020-05-12
        • 1970-01-01
        相关资源
        最近更新 更多