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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1983,7 +1983,6 @@
|
||||
"integrity": "sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/lodash": "*"
|
||||
}
|
||||
@@ -1994,7 +1993,6 @@
|
||||
"integrity": "sha512-DZ8VwRFUNzuqJ5khrvwMXHmvPe+zGayJhr2CDNiKB1WBE1ST8Djl00D0IC4vvNmHMdj6DlbYRIaFE7WHjlDl5w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"undici-types": "~7.16.0"
|
||||
}
|
||||
@@ -2041,7 +2039,6 @@
|
||||
"integrity": "sha512-BtE0k6cjwjLZoZixN0t5AKP0kSzlGu7FctRXYuPAm//aaiZhmfq1JwdYpYr1brzEspYyFeF+8XF5j2VK6oalrA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "8.54.0",
|
||||
"@typescript-eslint/types": "8.54.0",
|
||||
@@ -2579,7 +2576,6 @@
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz",
|
||||
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
},
|
||||
@@ -3120,7 +3116,6 @@
|
||||
"integrity": "sha512-LEyamqS7W5HB3ujJyvi0HQK/dtVINZvd5mAAp9eT5S/ujByGjiZLCzPcHVzuXbpJDJF/cxwHlfceVUDZ2lnSTw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.8.0",
|
||||
"@eslint-community/regexpp": "^4.12.1",
|
||||
@@ -3801,7 +3796,6 @@
|
||||
"integrity": "sha512-ekilCSN1jwRvIbgeg/57YFh8qQDNbwDb9xT/qu2DAHbFFZUicIl4ygVaAvzveMhMVr3LnpSKTNnwt8PoOfmKhQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"jiti": "lib/jiti-cli.mjs"
|
||||
}
|
||||
@@ -3926,16 +3920,14 @@
|
||||
"resolved": "https://registry.npmmirror.com/lodash/-/lodash-4.17.23.tgz",
|
||||
"integrity": "sha512-LgVTMpQtIopCi79SJeDiP0TfWi5CNEc/L/aRdTh3yIvmZXTnheWpKjSZhnvMl8iXbC1tFg9gdHHDMLoV7CnG+w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash-es": {
|
||||
"version": "4.17.23",
|
||||
"resolved": "https://registry.npmmirror.com/lodash-es/-/lodash-es-4.17.23.tgz",
|
||||
"integrity": "sha512-kVI48u3PZr38HdYz98UmfPnXl2DXrpdctLrFLCd3kOx1xUkOmpFPx7gCWWM5MPkL/fD8zb+Ph0QzjGFs4+hHWg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash-unified": {
|
||||
"version": "1.0.3",
|
||||
@@ -4507,7 +4499,6 @@
|
||||
"integrity": "sha512-fDz1zJpd5GycprAbu4Q2PV/RprsRtKC/0z82z0JLgdytmcq0+ujJbJ/09bPGDxCLkKY3Np5cRAOcWiVkLXJURg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"chokidar": "^4.0.0",
|
||||
"immutable": "^5.0.2",
|
||||
@@ -4694,7 +4685,6 @@
|
||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||
"devOptional": true,
|
||||
"license": "Apache-2.0",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
@@ -4803,7 +4793,6 @@
|
||||
"integrity": "sha512-w+N7Hifpc3gRjZ63vYBXA56dvvRlNWRczTdmCBBa+CotUzAPf5b7YMdMR/8CQoeYE5LX3W4wj6RYTgonm1b9DA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"esbuild": "^0.27.0",
|
||||
"fdir": "^6.5.0",
|
||||
@@ -4885,7 +4874,6 @@
|
||||
"resolved": "https://registry.npmmirror.com/vue/-/vue-3.5.27.tgz",
|
||||
"integrity": "sha512-aJ/UtoEyFySPBGarREmN4z6qNKpbEguYHMmXSiOGk69czc+zhs0NF6tEFrY8TZKAl8N/LYAkd4JHVd5E/AsSmw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@vue/compiler-dom": "3.5.27",
|
||||
"@vue/compiler-sfc": "3.5.27",
|
||||
@@ -4909,7 +4897,6 @@
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"vue-demi-fix": "bin/vue-demi-fix.js",
|
||||
"vue-demi-switch": "bin/vue-demi-switch.js"
|
||||
@@ -4936,7 +4923,6 @@
|
||||
"integrity": "sha512-CydUvFOQKD928UzZhTp4pr2vWz1L+H99t7Pkln2QSPdvmURT0MoC4wUccfCnuEaihNsu9aYYyk+bep8rlfkUXw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"debug": "^4.4.0",
|
||||
"eslint-scope": "^8.2.0",
|
||||
|
||||
@@ -18,6 +18,7 @@ interface RegulatoryData {
|
||||
}
|
||||
|
||||
interface RegulatoryFile {
|
||||
regulatory_file_name_original: string;
|
||||
regulatory_file_name: string;
|
||||
file_url: string;
|
||||
local_file_path: string;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: Kane Wang <wangkane@qq.com>
|
||||
* @Date: 2025-11-21 10:19:11
|
||||
* @LastEditors: Kane Wang
|
||||
* @LastModified: 2025-11-27 17:41:28
|
||||
* @LastModified: 2026-02-06 17:43:15
|
||||
* @FilePath: src/types/upload_file.ts
|
||||
* @Description:
|
||||
*
|
||||
@@ -18,6 +18,7 @@ interface UploadFileResponse
|
||||
|
||||
interface UploadedFile
|
||||
{
|
||||
originFileName: string;
|
||||
fileName: string;
|
||||
absoluteFilePath: string;
|
||||
relativeFilePath: string;
|
||||
|
||||
@@ -383,6 +383,7 @@ export default {
|
||||
}
|
||||
|
||||
const uploadedFile: RegulatoryFile = {
|
||||
regulatory_file_name_original: response.fileList[0].originFileName ?? "",
|
||||
regulatory_file_name: response.fileList[0].fileName ?? "",
|
||||
local_file_path: response.fileList[0]?.absoluteFilePath ?? "",
|
||||
file_type: getFileType( response.fileList[0]?.fileName ),
|
||||
|
||||
Reference in New Issue
Block a user