|
|
@@ -7,6 +7,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
@@ -31,7 +33,6 @@ public class FileController {
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("文件删除失败");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
// 获取文件列表,支持分页和搜索
|
|
|
@GetMapping
|
|
|
public ResponseEntity<List<String>> listFiles(
|
|
|
@@ -86,17 +87,21 @@ public class FileController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 文件下载
|
|
|
@GetMapping("/download/{filename}")
|
|
|
public ResponseEntity<byte[]> downloadFile(@PathVariable String filename) {
|
|
|
try {
|
|
|
Path path = Paths.get(uploadDir + filename);
|
|
|
byte[] data = Files.readAllBytes(path);
|
|
|
+
|
|
|
+ // 对文件名进行编码
|
|
|
+ String encodedFilename = URLEncoder.encode(filename, StandardCharsets.UTF_8.toString());
|
|
|
+
|
|
|
return ResponseEntity.ok()
|
|
|
- .header("Content-Disposition", "attachment; filename=\"" + filename + "\"")
|
|
|
+ .header("Content-Disposition", "attachment; filename=\"" + encodedFilename + "\"; filename*=UTF-8''" + encodedFilename)
|
|
|
.body(data);
|
|
|
} catch (IOException e) {
|
|
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|