From 879c9e5ad868a84a8ab23d5a5df302db18562e76 Mon Sep 17 00:00:00 2001 From: shierote Date: Sat, 1 Oct 2022 17:11:05 +0900 Subject: [PATCH] Fix a 404 test case --- .../java/com/example/uploadingfiles/FileUploadController.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/complete/src/main/java/com/example/uploadingfiles/FileUploadController.java b/complete/src/main/java/com/example/uploadingfiles/FileUploadController.java index 577e15e..a529b69 100644 --- a/complete/src/main/java/com/example/uploadingfiles/FileUploadController.java +++ b/complete/src/main/java/com/example/uploadingfiles/FileUploadController.java @@ -48,6 +48,10 @@ public String listUploadedFiles(Model model) throws IOException { public ResponseEntity serveFile(@PathVariable String filename) { Resource file = storageService.loadAsResource(filename); + + if (file == null) + return ResponseEntity.notFound().build(); + return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getFilename() + "\"").body(file); }