保存进度!
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* @Author: Kane Wang <wangkane@qq.com>
|
||||
* @Date: 2025-10-16 09:46:42
|
||||
* @LastEditors: Kane Wang
|
||||
* @LastModified: 2025-11-13 15:25:07
|
||||
* @LastModified: 2025-11-14 11:17:39
|
||||
* @FilePath: src/main/java/com/cpic/xim/utils/files/SaveUploadFile.java
|
||||
* @Description:
|
||||
*
|
||||
@@ -80,6 +80,13 @@ public class SaveUploadFile
|
||||
return savedFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将files参数中上传的文件,保存到tempFilePath指定的路径,文件名加上毫秒数避免重复。
|
||||
* @param files
|
||||
* @param tempFilePath
|
||||
* @return 返回UploadedFile对象数组
|
||||
* @throws ProcessUploadedFileException
|
||||
*/
|
||||
public static Vector<UploadedFile> saveUploadFiles(
|
||||
MultipartFile[] files,
|
||||
String tempFilePath
|
||||
@@ -143,6 +150,20 @@ public class SaveUploadFile
|
||||
String newFilePath
|
||||
) throws MoveUploadedFileException
|
||||
{
|
||||
// 防御性验证
|
||||
File originFile = new File( originFilePath );
|
||||
File dest = new File( newFilePath );
|
||||
|
||||
// 文件如果不存在就抛出异常
|
||||
if ( originFile.exists() == false )
|
||||
{
|
||||
throw new MoveUploadedFileException("文件不存在!");
|
||||
}
|
||||
|
||||
|
||||
if ( originFile.renameTo(dest) == false )
|
||||
{
|
||||
throw new MoveUploadedFileException("移动文件失败!" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class FileUpload
|
||||
*/
|
||||
@RequestMapping( path = "/file-upload.do" )
|
||||
@ResponseBody
|
||||
public FileUploadResult saveUploadFile(
|
||||
public UploadFileResult saveUploadFile(
|
||||
@RequestParam( "file-name" ) String fileName,
|
||||
@RequestParam( "files" ) MultipartFile file,
|
||||
HttpServletRequest request
|
||||
@@ -52,7 +52,7 @@ public class FileUpload
|
||||
{
|
||||
// session id用来创建临时目录,避免重复
|
||||
String sessionID = request.getSession().getId();
|
||||
FileUploadResult result = new FileUploadResult();
|
||||
UploadFileResult result = new UploadFileResult();
|
||||
MultipartFile[] files = new MultipartFile[1];
|
||||
|
||||
result.setSuccess( true );
|
||||
@@ -86,4 +86,6 @@ public class FileUpload
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// public
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @Author: Kane Wang <wangkane@qq.com>
|
||||
* @Date: 2025-11-17 17:49:58
|
||||
* @LastEditors: Kane Wang
|
||||
* @LastModified: 2025-11-17 18:11:27
|
||||
* @FilePath: src/main/java/com/cpic/xim/web/controllers/fileupload/MoveFileRequest.java
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) 2025 by Kane All rights reserved
|
||||
*/
|
||||
package com.cpic.xim.web.controllers.fileupload;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class MoveFileRequest
|
||||
{
|
||||
@JsonProperty("origin-file-path")
|
||||
private String originFilePath;
|
||||
|
||||
@JsonProperty("dest-file-path")
|
||||
private String destFilePath;
|
||||
|
||||
public MoveFileRequest()
|
||||
{
|
||||
originFilePath = "";
|
||||
destFilePath = "";
|
||||
}
|
||||
|
||||
public MoveFileRequest( String originFilePath, String destFilePath )
|
||||
{
|
||||
this.originFilePath = originFilePath;
|
||||
this.destFilePath = destFilePath;
|
||||
}
|
||||
|
||||
public String getOriginFilePath()
|
||||
{
|
||||
return originFilePath;
|
||||
}
|
||||
|
||||
public void setOriginFilePath( String originFilePath )
|
||||
{
|
||||
this.originFilePath = originFilePath;
|
||||
}
|
||||
|
||||
public String getDestFilePath()
|
||||
{
|
||||
return destFilePath;
|
||||
}
|
||||
|
||||
public void setDestFilePath( String destFilePath )
|
||||
{
|
||||
this.destFilePath = destFilePath;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @Author: Kane Wang <wangkane@qq.com>
|
||||
* @Date: 2025-11-17 17:31:15
|
||||
* @LastEditors: Kane Wang
|
||||
* @LastModified: 2025-11-17 17:31:16
|
||||
* @FilePath: src/main/java/com/cpic/xim/web/controllers/fileupload/MoveFileResult.java
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) 2025 by Kane All rights reserved
|
||||
*/
|
||||
package com.cpic.xim.web.controllers.fileupload;
|
||||
|
||||
import com.cpic.xim.web.controllers.QueryResponse;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class MoveFileResult extends QueryResponse
|
||||
{
|
||||
|
||||
@JsonProperty("new-file-path")
|
||||
private String newFilePath;
|
||||
|
||||
public MoveFileResult()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public MoveFileResult(
|
||||
boolean success,
|
||||
String message,
|
||||
String newFilePath
|
||||
)
|
||||
{
|
||||
super( success, message );
|
||||
|
||||
this.newFilePath = newFilePath;
|
||||
}
|
||||
|
||||
public String getNewFilePath()
|
||||
{
|
||||
return newFilePath;
|
||||
}
|
||||
|
||||
public void setNewFilePath( String newFilePath )
|
||||
{
|
||||
this.newFilePath = newFilePath;
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,9 @@ import com.cpic.xim.web.controllers.QueryResponse;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@SuppressWarnings( "unused" )
|
||||
public class FileUploadResult extends QueryResponse
|
||||
public class UploadFileResult extends QueryResponse
|
||||
{
|
||||
public FileUploadResult()
|
||||
public UploadFileResult()
|
||||
{
|
||||
super();
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class FileUploadResult extends QueryResponse
|
||||
* @param message 消息字符串
|
||||
* @param fileList 文件绝对路径字符串数组
|
||||
*/
|
||||
public FileUploadResult(
|
||||
public UploadFileResult(
|
||||
boolean success,
|
||||
String message,
|
||||
Vector<UploadedFile> fileList
|
||||
@@ -15,7 +15,7 @@
|
||||
"devDependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.2",
|
||||
"@stylistic/eslint-plugin": "^5.5.0",
|
||||
"@types/node": "^24.9.2",
|
||||
"@types/node": "^24.10.1",
|
||||
"@typescript-eslint/eslint-plugin": "^8.46.4",
|
||||
"@typescript-eslint/parser": "^8.46.4",
|
||||
"@vitejs/plugin-vue": "^6.0.1",
|
||||
@@ -24,7 +24,7 @@
|
||||
"@vue-office/pdf": "^2.0.10",
|
||||
"@vue/tsconfig": "^0.8.1",
|
||||
"axios": "^1.13.2",
|
||||
"element-plus": "^2.11.7",
|
||||
"element-plus": "^2.11.8",
|
||||
"eslint": "^9.39.1",
|
||||
"eslint-plugin-vue": "^10.5.1",
|
||||
"path": "^0.12.7",
|
||||
@@ -34,7 +34,7 @@
|
||||
"vue-demi": "^0.14.10",
|
||||
"vue-eslint-parser": "^10.2.0",
|
||||
"vue-pdf-embed": "^2.1.3",
|
||||
"vue-tsc": "^3.1.3"
|
||||
"vue-tsc": "^3.1.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-string-parser": {
|
||||
@@ -1744,9 +1744,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "24.9.2",
|
||||
"resolved": "https://registry.npmmirror.com/@types/node/-/node-24.9.2.tgz",
|
||||
"integrity": "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA==",
|
||||
"version": "24.10.1",
|
||||
"resolved": "https://registry.npmmirror.com/@types/node/-/node-24.10.1.tgz",
|
||||
"integrity": "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
@@ -2154,9 +2154,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@vue/language-core": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmmirror.com/@vue/language-core/-/language-core-3.1.3.tgz",
|
||||
"integrity": "sha512-KpR1F/eGAG9D1RZ0/T6zWJs6dh/pRLfY5WupecyYKJ1fjVmDMgTPw9wXmKv2rBjo4zCJiOSiyB8BDP1OUwpMEA==",
|
||||
"version": "3.1.4",
|
||||
"resolved": "https://registry.npmmirror.com/@vue/language-core/-/language-core-3.1.4.tgz",
|
||||
"integrity": "sha512-n/58wm8SkmoxMWkUNUH/PwoovWe4hmdyPJU2ouldr3EPi1MLoS7iDN46je8CsP95SnVBs2axInzRglPNKvqMcg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -2622,9 +2622,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/element-plus": {
|
||||
"version": "2.11.7",
|
||||
"resolved": "https://registry.npmmirror.com/element-plus/-/element-plus-2.11.7.tgz",
|
||||
"integrity": "sha512-Bh47wuzsqaNBNDkbtlOlZER1cGcOB8GsXp/+C9b95MOrk0wvoHUV4NKKK7xMkfYNFYdYysQ752oMhnExgAL6+g==",
|
||||
"version": "2.11.8",
|
||||
"resolved": "https://registry.npmmirror.com/element-plus/-/element-plus-2.11.8.tgz",
|
||||
"integrity": "sha512-2wzSj2uubFU1f0t/gHkkE1d09mUgV18fSZX5excw3Ar6hyWcxph4E57U8dgYLDt7HwkKYv1BiqPyBdy0WqWlOA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -4477,14 +4477,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/vue-tsc": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmmirror.com/vue-tsc/-/vue-tsc-3.1.3.tgz",
|
||||
"integrity": "sha512-StMNfZHwPIXQgY3KxPKM0Jsoc8b46mDV3Fn2UlHCBIwRJApjqrSwqeMYgWf0zpN+g857y74pv7GWuBm+UqQe1w==",
|
||||
"version": "3.1.4",
|
||||
"resolved": "https://registry.npmmirror.com/vue-tsc/-/vue-tsc-3.1.4.tgz",
|
||||
"integrity": "sha512-GsRJxttj4WkmXW/zDwYPGMJAN3np/4jTzoDFQTpTsI5Vg/JKMWamBwamlmLihgSVHO66y9P7GX+uoliYxeI4Hw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@volar/typescript": "2.4.23",
|
||||
"@vue/language-core": "3.1.3"
|
||||
"@vue/language-core": "3.1.4"
|
||||
},
|
||||
"bin": {
|
||||
"vue-tsc": "bin/vue-tsc.js"
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"devDependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.2",
|
||||
"@stylistic/eslint-plugin": "^5.5.0",
|
||||
"@types/node": "^24.9.2",
|
||||
"@types/node": "^24.10.1",
|
||||
"@typescript-eslint/eslint-plugin": "^8.46.4",
|
||||
"@typescript-eslint/parser": "^8.46.4",
|
||||
"@vitejs/plugin-vue": "^6.0.1",
|
||||
@@ -25,7 +25,7 @@
|
||||
"@vue-office/pdf": "^2.0.10",
|
||||
"@vue/tsconfig": "^0.8.1",
|
||||
"axios": "^1.13.2",
|
||||
"element-plus": "^2.11.7",
|
||||
"element-plus": "^2.11.8",
|
||||
"eslint": "^9.39.1",
|
||||
"eslint-plugin-vue": "^10.5.1",
|
||||
"path": "^0.12.7",
|
||||
@@ -35,6 +35,6 @@
|
||||
"vue-demi": "^0.14.10",
|
||||
"vue-eslint-parser": "^10.2.0",
|
||||
"vue-pdf-embed": "^2.1.3",
|
||||
"vue-tsc": "^3.1.3"
|
||||
"vue-tsc": "^3.1.4"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user