- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
HTMLInputElement.webkitdirectory是属于<input>
元素的一个HTML属性webkitdirectory,它可以选择一个文件夹,文件夹里的文件夹和文件都可以上传上去。,但是这个属性不是标准化的,不适用于IE浏览器和火狐浏览器。
详情可以参考webkitdirectory
spring.servlet.multipart.max-file-size=1000MB
spring.servlet.multipart.max-request-size=1000MB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Files Uploader</title>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<form action="/uploadFolder" method="post" enctype="multipart/form-data">
<input id="folder" type="file" name="folder" multiple webkitdirectory>
<button type="submit">上传</button>
</form>
<script type="text/javascript">
function uploadFiles(){
$.post("/uploadFolder",{
folder: $("#folder")
},function(result){
if(result=="success"){
alert("success");
location.reload();
}else{
alert("failed");
}
})
}
</script>
</body>
</html>
页面操作:
public class FileUtil {
/**
* 在basePath下保存上传的文件夹
*
* @param basePath
* @param files
*/
public static void saveMultiFile(String basePath, MultipartFile[] files) {
if (files == null || files.length == 0) {
System.out.println("no files uploaded");
return;
} else if (files[0].getOriginalFilename() == null || files[0].getOriginalFilename().equals("")) {
System.out.println("Empty package: no files to be uploaded");
return;
}
if (basePath.endsWith("/")) {
basePath = basePath.substring(0, basePath.length() - 1);
}
for (MultipartFile file : files) {
String relativePath = file.getOriginalFilename();
String filePath = basePath + "/" + relativePath;
System.out.println("uploading " + relativePath + " to " + filePath + "......");
makeDir(filePath);
File dest = new File(filePath);
try {
file.transferTo(dest);
System.out.println("successful upload");
} catch (IllegalStateException | IOException e) {
e.printStackTrace();
}
}
}
/**
* 确保目录存在,不存在则创建
*
* @param filePath
*/
private static void makeDir(String filePath) {
if (filePath.lastIndexOf('/') > 0) {
String dirPath = filePath.substring(0, filePath.lastIndexOf('/'));
File dir = new File(dirPath);
if (!dir.exists()) {
dir.mkdirs();
}
}
}
}
@RestController
public class UploadFileController {
@PostMapping(value = "/uploadFolder")
public String uploadFolder(@RequestParam MultipartFile[] folder) {
FileUtil.saveMultiFile("G:\\temp", folder);
return "success";
}
}
我想允许用户选择一个目录(我在其中解析一些文本文件)并存储 result(List)在 PERSISTENT存储在同一个客户端,这样当用户返回时,无需再次选择相同的目录。 在 session 期间选择
我正忙于构建一个从我的本地文件系统中提取的小型画廊。我有一个获取目录的元素: 然后我在容器中的页面上显示该目录中的所有图像和视频。 目前出于安全原因,我只能访问相对路径,所以我必须添加一个硬
我正在尝试使用 HTML5 Files API 和 JavaScript 通过 webkitdirectory 属性运行大量上传。 理想情况下,最终用户可以通过一次操作上传整个硬盘驱动器。我在一个文
我正在使用 webkitdirectory创建一个允许上传整个文件夹(而不是选择单个文件)的输入。我知道它是非标准的,不应在生产中使用。 我正在上传一种特定类型的文件夹,其中有一个不需要的非常大的文件
我正在尝试使用输入类型文件上传目录。它在 GoogleChrome 和 FireFox 中工作正常,但是当我在 Safari 浏览器中测试它时,它无法正常工作,它也允许用户选择单个文件。有什么方法可以
在我的网络应用程序中,我在输入字段上使用文件夹选择。这就是功能 https://caniuse.com/#search=webkitdirectory 但是,我还进行了一些兼容性检查,以确保该功能在用
我正在尝试使用文件夹输入而不是文件输入。我想选择一个文件夹,而不仅仅是一个文件。我从已经提出的问题中尝试了可用的解决方案,但没有一个有效。这是我尝试过的 试过 面临的问题 1)。我正在处理 rea
我正在尝试在输入元素中使用 HTML5 文件 api + webkitdirectory。 如何使用 javascript/jquery 获取所选文件夹/目录的大小(以 kb/mb 等为单位)。 请
我最近对 Google Chrome 进行了大量研究,浏览了测试版页面,但我找不到关于这个特定主题的任何文档。我有一个使用 webkitdirectory 方法的网络应用程序: 并且适用于 Go
我是一名优秀的程序员,十分优秀!