File tree Expand file tree Collapse file tree
src/main/java/com/cognizant/controller Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ public class CommentAndAttachmentController {
4949
5050 // Where uploaded files are saved on disk
5151 // Set this in application.properties: app.upload.dir=./uploads
52- @ Value ("${app.upload.dir:. /uploads}" )
52+ @ Value ("${app.upload.dir:/home /uploads}" )
5353 private String uploadDir ;
5454
5555 public CommentAndAttachmentController (
@@ -193,7 +193,9 @@ public ResponseEntity<?> uploadAttachment(
193193 // 4. Save file to disk
194194 try {
195195 Path uploadPath = Paths .get (uploadDir ).toAbsolutePath ().normalize ();
196- Files .createDirectories (uploadPath );
196+ if (!Files .exists (uploadPath )) {
197+ Files .createDirectories (uploadPath );
198+ }
197199
198200 // Generate a unique filename to avoid collisions
199201 String original = file .getOriginalFilename ();
@@ -232,7 +234,7 @@ public ResponseEntity<Resource> downloadAttachment(@PathVariable String storedNa
232234 Path filePath = Paths .get (uploadDir ).toAbsolutePath ().normalize ().resolve (storedName );
233235 Resource resource = new UrlResource (filePath .toUri ());
234236
235- if (!resource .exists ()) {
237+ if (!resource .exists () || ! resource . isReadable () ) {
236238 return ResponseEntity .notFound ().build ();
237239 }
238240
You can’t perform that action at this time.
0 commit comments