保存进度!

This commit is contained in:
2025-11-17 19:00:39 +08:00
parent 1b40137cf9
commit 5d7aee0e7c
7 changed files with 150 additions and 25 deletions

View File

@@ -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("移动文件失败!" );
}
}
}

View File

@@ -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
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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