diff --git a/src/main/java/com/ramostear/application/controller/FileController.java b/src/main/java/com/ramostear/application/controller/FileController.java index 5aaf860..fcb924e 100644 --- a/src/main/java/com/ramostear/application/controller/FileController.java +++ b/src/main/java/com/ramostear/application/controller/FileController.java @@ -15,6 +15,7 @@ import javax.annotation.PostConstruct; import java.io.*; +import java.net.URLEncoder; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -90,13 +91,14 @@ public String fileUpload(@RequestParam("file") MultipartFile file) throws IOExce @GetMapping("/download/{fileName}") @ResponseBody - public ResponseEntity downloadFile(@PathVariable(name = "fileName") String fileName) throws FileNotFoundException { + public ResponseEntity downloadFile(@PathVariable(name = "fileName") String fileName) throws FileNotFoundException, UnsupportedEncodingException { File file = new File ( fileUploadRootDir+fileName); InputStreamResource resource = new InputStreamResource ( new FileInputStream ( file ) ); HttpHeaders headers = new HttpHeaders(); - headers.add ( "Content-Disposition",String.format("attachment;filename=\"%s",fileName)); + // 使用URLEncoder.encode(fileName, "UTF-8") 下载文件能正常显示中文 + headers.add ( "Content-Disposition",String.format("attachment;filename=\"%s", URLEncoder.encode(fileName, "UTF-8"))); headers.add ( "Cache-Control","no-cache,no-store,must-revalidate" ); headers.add ( "Pragma","no-cache" ); headers.add ( "Expires","0" ); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index b69e90b..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,9 +0,0 @@ -spring.freemarker.cache=false -spring.freemarker.prefix= -spring.freemarker.suffix=.html -spring.freemarker.enabled=true -spring.freemarker.charset=UTF-8 -spring.freemarker.template-loader-path=classpath:/templates/ -file.upload.root.dir.windows = C:/work/upload/ -file.upload.root.dir.mac = ~/upload/ -file.upload.root.dir.linux = ~/upload/ \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..92e68dc --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,19 @@ +spring: + freemarker: + cache: false + charset: UTF-8 + enabled: true + prefix: '' + suffix: .html + template-loader-path: classpath:/templates/ + servlet: + multipart: + max-file-size: 100MB + max-request-size: 1000MB +file: + upload: + root: + dir: + linux: ~/upload/ + mac: /users/gaohanghang/upload/ + windows: C:/work/upload/