Skip to content

Commit 626dfb8

Browse files
authored
Update CommentAndAttachmentController.java
1 parent ed6f523 commit 626dfb8

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/main/java/com/cognizant/controller/CommentAndAttachmentController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)