1、增加文件名中特殊字符编码功能,防止生成url时出现错误。
2、前端加入保留文件名原名。
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-12-01 18:42:31
|
||||
* @LastModified: 2026-02-06 19:08:46
|
||||
* @FilePath: src/main/java/com/cpic/xim/utils/files/SaveUploadFile.java
|
||||
* @Description:
|
||||
*
|
||||
@@ -128,7 +128,7 @@ public class SaveUploadFile
|
||||
|
||||
file.transferTo( destFile );
|
||||
|
||||
uploadedFile = new UploadedFile( fileName, fullPath, relativeFilePath );
|
||||
uploadedFile = new UploadedFile( file.getOriginalFilename(), fileName, fullPath, relativeFilePath );
|
||||
|
||||
savedFiles.add( uploadedFile );
|
||||
}
|
||||
@@ -175,4 +175,54 @@ public class SaveUploadFile
|
||||
throw new MoveUploadedFileException( "移动文件失败!" );
|
||||
}
|
||||
}
|
||||
|
||||
public static String encodeFileName( String originalFileName )
|
||||
{
|
||||
StringBuilder encodedFileName = new StringBuilder( originalFileName.length() * 3 );
|
||||
char[] charArray = originalFileName.toCharArray();
|
||||
|
||||
for ( char c : charArray )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
case '%':
|
||||
encodedFileName.append( PERCENT );
|
||||
break;
|
||||
case ' ':
|
||||
encodedFileName.append( SPACING );
|
||||
break;
|
||||
case '+':
|
||||
encodedFileName.append( PLUS );
|
||||
break;
|
||||
case '/':
|
||||
encodedFileName.append( FORWARD_SLASH );
|
||||
break;
|
||||
case '?':
|
||||
encodedFileName.append( QUESTION_MASK );
|
||||
break;
|
||||
case '&':
|
||||
encodedFileName.append( AMPERSAND );
|
||||
break;
|
||||
case '#':
|
||||
encodedFileName.append( SHARP );
|
||||
break;
|
||||
case '=':
|
||||
encodedFileName.append( PLUS );
|
||||
break;
|
||||
default:
|
||||
encodedFileName.append( c );
|
||||
}
|
||||
}
|
||||
|
||||
return encodedFileName.toString();
|
||||
}
|
||||
|
||||
static final String SHARP = "%23";
|
||||
static final String PLUS = "%2B";
|
||||
static final String FORWARD_SLASH = "%2F";
|
||||
static final String QUESTION_MASK = "%3F";
|
||||
static final String SPACING = "%20";
|
||||
static final String EQUAL = "%3D";
|
||||
static final String PERCENT = "%25";
|
||||
static final String AMPERSAND = "%26";
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: Kane Wang <wangkane@qq.com>
|
||||
* @Date: 2025-10-31 17:33:13
|
||||
* @LastEditors: Kane Wang
|
||||
* @LastModified: 2025-12-26 21:58:32
|
||||
* @LastModified: 2026-02-06 17:41:44
|
||||
* @FilePath: src/main/java/com/cpic/xim/utils/files/UploadedFile.java
|
||||
* @Description:
|
||||
*
|
||||
@@ -18,6 +18,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
*/
|
||||
public class UploadedFile
|
||||
{
|
||||
@JsonProperty("originFileName")
|
||||
private String originFileName;
|
||||
|
||||
@JsonProperty( "fileName" )
|
||||
private String fileName;
|
||||
|
||||
@@ -60,17 +63,21 @@ public class UploadedFile
|
||||
public UploadedFile()
|
||||
{}
|
||||
|
||||
public UploadedFile( String fileName, String absoluteFilePath, String relativeFilePath )
|
||||
public UploadedFile( String originFileName, String fileName, String absoluteFilePath, String relativeFilePath )
|
||||
{
|
||||
this.originFileName = originFileName;
|
||||
this.fileName = fileName;
|
||||
this.absoluteFilePath = absoluteFilePath;
|
||||
this.relativeFilePath = relativeFilePath;
|
||||
}
|
||||
|
||||
public UploadedFile( String fileName, String absoluteFilePath )
|
||||
public String getOriginFileName()
|
||||
{
|
||||
this.fileName = fileName;
|
||||
this.absoluteFilePath = absoluteFilePath;
|
||||
this.relativeFilePath = "";
|
||||
return originFileName;
|
||||
}
|
||||
|
||||
public void setOriginFileName( String originFileName )
|
||||
{
|
||||
this.originFileName = originFileName;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user