使用Compojure,打ic和铃声上传多个文件 [英] Using Compojure, Hiccup and Ring to upload MULTIPLE files

查看:82
本文介绍了使用Compojure,打ic和铃声上传多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这确实是使用Compojure,Hiccup的翻版和Ring来上传文件



如果有多个标签:

 < form action = / file method = post enctype = multipart / form-data> 
<输入名称=文件 type =文件 size = 20倍数/>
<输入类型=提交 name =提交 value =提交 />

如何使用ring获取所有文件的值?

解决方案

我创建了一个测试项目,并检查了提交多个文件时到达后端的请求映射所包含的数据类型。以下是请求映射的一部分:

  {:multipart-params { submit提交,
文件 [{:size 439,
:tempfile#<文件/tmp/ring-multipart-5216436296043515515206.tmp>,
:内容类型应用程序/ javascript,
:文件名bar.js }
{:size 24,
:tempfile#< File /tmp/ring-multipart-3573753728611312574.tmp> ;,
:content-type application / octet-stream,
:filename foo.md}],...}

似乎是(进入请求[:multipart-params file])将为您提供上载文件的向量,其中包含有关其原始文件名和类型以及临时存储位置的信息。根据 Ring的文档,文件将被存储一小时。 p>

This is really a rip off of Using Compojure, Hiccup and Ring to upload a file

If there is a multiple tag:

<form action="/file" method="post" enctype="multipart/form-data">
  <input name="file" type="file" size="20" multiple/>
<input type="submit" name="submit" value="submit" />

How would one go about getting the values of all the files using ring?

解决方案

I created a test project and checked what sort of data the request map contains when arriving to the back-end when submitting multiple files. Below is a part of the request map:

{:multipart-params {"submit" submit,
                    "file" [{:size 439,
                             :tempfile #<File /tmp/ring-multipart-5216436296043515206.tmp>,
                             :content-type application/javascript,
                             :filename bar.js}
                            {:size 24,
                             :tempfile #<File /tmp/ring-multipart-3573753728611312574.tmp>,
                             :content-type application/octet-stream,
                             :filename foo.md}], ...}

Seems that (get-in request [:multipart-params "file"]) would give you a vector of the uploaded files, containing information on what their original file names and types were and where they are temporarily stored. According to Ring's documentation the files will be stored for one hour.

这篇关于使用Compojure,打ic和铃声上传多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆