fix(back-end): file error handling
All checks were successful
Build, Test and Deploy / test-backend (push) Successful in 32s
Build, Test and Deploy / build-and-push (push) Successful in 31s
Build, Test and Deploy / deploy (push) Successful in 6s

This commit is contained in:
2026-02-16 15:07:21 +01:00
parent 9b24ca529c
commit a96c28fb39
2 changed files with 5 additions and 10 deletions

View File

@@ -43,21 +43,16 @@ public class FileSystemStorageService implements StorageService {
throw new StorageException("Cannot store file outside current directory.");
}
// Scan stream
// Scan stream (Read 1)
try (InputStream inputStream = file.getInputStream()) {
if (!clamAVService.scan(inputStream)) {
throw new StorageException("File rejected by antivirus scanner.");
}
}
// Reset stream? MultipartFile.getInputStream() returns a new stream usually,
// but let's verify if we need to open it again.
// Yes, we consumed the stream for scanning. We need to open it again for copying.
try (InputStream inputStream = file.getInputStream()) {
Files.createDirectories(destinationFile.getParent());
Files.copy(inputStream, destinationFile, StandardCopyOption.REPLACE_EXISTING);
}
// Save to disk (Using transferTo which is safer than opening another stream)
Files.createDirectories(destinationFile.getParent());
file.transferTo(destinationFile.toFile());
}
@Override

View File

@@ -99,7 +99,7 @@ public class SlicerService {
// File da processare (sempre per ultimo)
command.add(localStl.getAbsolutePath());
logger.info("Executing Slicer: " + String.join(" ", command));
logger.info("Executing Slicer on file: " + localStl.getAbsolutePath() + " (Size: " + localStl.length() + " bytes)");
runSlicerCommand(command, tempDir);