如何在Spring Web应用程序中实现文件夹上传? [英] How to implement folder upload in a Spring web app?

查看:56
本文介绍了如何在Spring Web应用程序中实现文件夹上传?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Web应用程序中实现类似于Google云端硬盘样式的文件/目录上传(我认为这是解释我想要的最好的例子).

I'd like to implement in my web application a file/directory upload similar to Google Drive style (I think it's the best example to explain what I want).

所以我想上传:

  • 单个文件
  • 多个选定文件
  • 选定的文件夹(其中包含的所有文件)

在客户端,我想我必须使用HTML5,对吗?但是如何在服务器端控制器上处理此问题.我正在使用Spring MVC 3.2.9

On client side I suppose I have to use HTML5, am I wrong? But How to handle this on server side controller. I'm using Spring MVC 3.2.9

您能建议我最好的方法吗?

Can you suggest me the best approach?

推荐答案

最困难的部分是客户端在客户端上载文件夹.根据关于SO的另一个答案,关于 HTML5是否允许拖放拖放文件夹或文件夹树?HTML5规范并未说明选择上传文件夹时,浏览器应递归上传所有包含的文件.

The hard part is the client side upload of folders. According to this other answer on SO about Does HTML5 allow drag-drop upload of folders or a folder tree?, The HTML5 spec does NOT say that when selecting a folder for upload, the browser should upload all contained files recursively.

当然可以,但是HTML5不够用,您将不得不使用Javascript(递归)查找文件夹中的所有文件.

Of course it is possible, but HTML5 is not enough and you will have to use Javascript to (recursively) find all files in the folder.

如conFusl所说,您可以在viralpatel.net上找到一个很好的示例

As said by conFusl, you can find a nice example on viralpatel.net Spring MVC Multiple File Upload tutorial. Spring Multiple File upload example. The princips are :

    客户端上的
  • 生成(通过javascript)一个表单,每个文件带有一个< input> 标记以上传,并为它们命名,例如 files [i]
  • 在服务器端,您将获得一个包含 List< MultipartFile> 的表单,您可以照常进行处理.
  • on client side generate (via javascript) a form with one <input> tag per file to upload, and give them names like files[i]
  • on server side, you then get a form containing a List<MultipartFile> that you can process as usual.

这篇关于如何在Spring Web应用程序中实现文件夹上传?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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