Compare commits
2 Commits
f2bc8d14ab
...
de0b396bcb
| Author | SHA1 | Date | |
|---|---|---|---|
| de0b396bcb | |||
| 5d7aee0e7c |
@@ -2,7 +2,7 @@
|
|||||||
* @Author: Kane Wang <wangkane@qq.com>
|
* @Author: Kane Wang <wangkane@qq.com>
|
||||||
* @Date: 2025-10-16 09:46:42
|
* @Date: 2025-10-16 09:46:42
|
||||||
* @LastEditors: Kane Wang
|
* @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
|
* @FilePath: src/main/java/com/cpic/xim/utils/files/SaveUploadFile.java
|
||||||
* @Description:
|
* @Description:
|
||||||
*
|
*
|
||||||
@@ -80,6 +80,13 @@ public class SaveUploadFile
|
|||||||
return savedFiles;
|
return savedFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将files参数中上传的文件,保存到tempFilePath指定的路径,文件名加上毫秒数避免重复。
|
||||||
|
* @param files
|
||||||
|
* @param tempFilePath
|
||||||
|
* @return 返回UploadedFile对象数组
|
||||||
|
* @throws ProcessUploadedFileException
|
||||||
|
*/
|
||||||
public static Vector<UploadedFile> saveUploadFiles(
|
public static Vector<UploadedFile> saveUploadFiles(
|
||||||
MultipartFile[] files,
|
MultipartFile[] files,
|
||||||
String tempFilePath
|
String tempFilePath
|
||||||
@@ -143,6 +150,20 @@ public class SaveUploadFile
|
|||||||
String newFilePath
|
String newFilePath
|
||||||
) throws MoveUploadedFileException
|
) 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" )
|
@RequestMapping( path = "/file-upload.do" )
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public FileUploadResult saveUploadFile(
|
public UploadFileResult saveUploadFile(
|
||||||
@RequestParam( "file-name" ) String fileName,
|
@RequestParam( "file-name" ) String fileName,
|
||||||
@RequestParam( "files" ) MultipartFile file,
|
@RequestParam( "files" ) MultipartFile file,
|
||||||
HttpServletRequest request
|
HttpServletRequest request
|
||||||
@@ -52,7 +52,7 @@ public class FileUpload
|
|||||||
{
|
{
|
||||||
// session id用来创建临时目录,避免重复
|
// session id用来创建临时目录,避免重复
|
||||||
String sessionID = request.getSession().getId();
|
String sessionID = request.getSession().getId();
|
||||||
FileUploadResult result = new FileUploadResult();
|
UploadFileResult result = new UploadFileResult();
|
||||||
MultipartFile[] files = new MultipartFile[1];
|
MultipartFile[] files = new MultipartFile[1];
|
||||||
|
|
||||||
result.setSuccess( true );
|
result.setSuccess( true );
|
||||||
@@ -86,4 +86,6 @@ public class FileUpload
|
|||||||
|
|
||||||
return result;
|
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;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
@SuppressWarnings( "unused" )
|
@SuppressWarnings( "unused" )
|
||||||
public class FileUploadResult extends QueryResponse
|
public class UploadFileResult extends QueryResponse
|
||||||
{
|
{
|
||||||
public FileUploadResult()
|
public UploadFileResult()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ public class FileUploadResult extends QueryResponse
|
|||||||
* @param message 消息字符串
|
* @param message 消息字符串
|
||||||
* @param fileList 文件绝对路径字符串数组
|
* @param fileList 文件绝对路径字符串数组
|
||||||
*/
|
*/
|
||||||
public FileUploadResult(
|
public UploadFileResult(
|
||||||
boolean success,
|
boolean success,
|
||||||
String message,
|
String message,
|
||||||
Vector<UploadedFile> fileList
|
Vector<UploadedFile> fileList
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
"vue-demi": "^0.14.10",
|
"vue-demi": "^0.14.10",
|
||||||
"vue-eslint-parser": "^10.2.0",
|
"vue-eslint-parser": "^10.2.0",
|
||||||
"vue-pdf-embed": "^2.1.3",
|
"vue-pdf-embed": "^2.1.3",
|
||||||
"vue-tsc": "^3.1.3"
|
"vue-tsc": "^3.1.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/helper-string-parser": {
|
"node_modules/@babel/helper-string-parser": {
|
||||||
@@ -2154,9 +2154,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@vue/language-core": {
|
"node_modules/@vue/language-core": {
|
||||||
"version": "3.1.3",
|
"version": "3.1.4",
|
||||||
"resolved": "https://registry.npmmirror.com/@vue/language-core/-/language-core-3.1.3.tgz",
|
"resolved": "https://registry.npmmirror.com/@vue/language-core/-/language-core-3.1.4.tgz",
|
||||||
"integrity": "sha512-KpR1F/eGAG9D1RZ0/T6zWJs6dh/pRLfY5WupecyYKJ1fjVmDMgTPw9wXmKv2rBjo4zCJiOSiyB8BDP1OUwpMEA==",
|
"integrity": "sha512-n/58wm8SkmoxMWkUNUH/PwoovWe4hmdyPJU2ouldr3EPi1MLoS7iDN46je8CsP95SnVBs2axInzRglPNKvqMcg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -4477,14 +4477,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/vue-tsc": {
|
"node_modules/vue-tsc": {
|
||||||
"version": "3.1.3",
|
"version": "3.1.4",
|
||||||
"resolved": "https://registry.npmmirror.com/vue-tsc/-/vue-tsc-3.1.3.tgz",
|
"resolved": "https://registry.npmmirror.com/vue-tsc/-/vue-tsc-3.1.4.tgz",
|
||||||
"integrity": "sha512-StMNfZHwPIXQgY3KxPKM0Jsoc8b46mDV3Fn2UlHCBIwRJApjqrSwqeMYgWf0zpN+g857y74pv7GWuBm+UqQe1w==",
|
"integrity": "sha512-GsRJxttj4WkmXW/zDwYPGMJAN3np/4jTzoDFQTpTsI5Vg/JKMWamBwamlmLihgSVHO66y9P7GX+uoliYxeI4Hw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@volar/typescript": "2.4.23",
|
"@volar/typescript": "2.4.23",
|
||||||
"@vue/language-core": "3.1.3"
|
"@vue/language-core": "3.1.4"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"vue-tsc": "bin/vue-tsc.js"
|
"vue-tsc": "bin/vue-tsc.js"
|
||||||
|
|||||||
@@ -35,6 +35,6 @@
|
|||||||
"vue-demi": "^0.14.10",
|
"vue-demi": "^0.14.10",
|
||||||
"vue-eslint-parser": "^10.2.0",
|
"vue-eslint-parser": "^10.2.0",
|
||||||
"vue-pdf-embed": "^2.1.3",
|
"vue-pdf-embed": "^2.1.3",
|
||||||
"vue-tsc": "^3.1.3"
|
"vue-tsc": "^3.1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user