要将文件上传到我用 Clojure 编写的服务器,我需要一个如下所示的客户端表单:
<form action="/file" method="post" enctype="multipart/form-data">
<input name="file" type="file" size="20" />
<input type="submit" name="submit" value="submit" />
但是我找不到 Hiccup 或 Compojure 的文档来创建这样的表单。我的样本看起来像这样:
[:h2 "Choose a file to upload"]
:form {:method "post" :action "/upload"}
[:input.math {:type "text" :name "a"}] [:span.math " + "]
[:input.math {:type "text" :name "b"}] [:br]
所以我的问题是哪里有文档可以找到如何修改它以制作上传文件的表单?
Compojure 的文件上传支持可以在multipart-params
环形中间件。以下是一些如何使用它的示例:
- https://gist.github.com/562624/1df418e4851e68952fc466713f377df2e653afdb https://gist.github.com/562624/1df418e4851e68952fc466713f377df2e653afdb
- http://www.prodevtips.com/2010/12/19/file-uploads-with-clojure-ring-and-compojure/ http://www.prodevtips.com/2010/12/19/file-uploads-with-clojure-ring-and-compojure/
经常查看 Ring 中间件文档,它充满了很棒的代码!
Update: 第一次没看清楚你的问题!要生成这样的表单:
<form action="/file" method="post" enctype="multipart/form-data">
<input name="file" type="file" size="20" />
<input type="submit" name="submit" value="submit" />
</form>
这应该够了吧:
[:form {:action "/file" :method "post" :enctype "multipart/form-data"}
[:input {:name "file" :type "file" :size "20"}]
[:input {:type "submit" :name "submit" :value "submit"]]
我是凭记忆做的,所以未经测试。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)