MultipartFile 文件名中的特殊字符转换为?在春季启动

BOU*_*LID 3 java file-upload spring-boot

我想知道为什么 spring boot 将 MultiPartFile 文件名特殊字符转换为 ?(例如 \xc3\xa9\xc3\xa9\xc3\xa9.pdf 转换为 ???.pdf)。我需要配置 Spring 来禁用此行为吗?我已经检查了我的 jvm 配置中的 file.encoding,它已经设置为 UTF-8。

\n\n

我这样执行文件上传:

\n\n
@PostMapping("/upload")\npublic void uploadFile(@RequestParam MultipartFile file){\n// todo : ...\n}\n
Run Code Online (Sandbox Code Playgroud)\n

A.k*_*ifa 5

你可以试试这个

 String originalFileName = URLDecoder.decode(file.getOriginalFilename(), "UTF-8");
Run Code Online (Sandbox Code Playgroud)

希望对你有用