fix(back-end): file error handling
This commit is contained in:
@@ -43,21 +43,16 @@ public class FileSystemStorageService implements StorageService {
|
|||||||
throw new StorageException("Cannot store file outside current directory.");
|
throw new StorageException("Cannot store file outside current directory.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan stream
|
// Scan stream (Read 1)
|
||||||
try (InputStream inputStream = file.getInputStream()) {
|
try (InputStream inputStream = file.getInputStream()) {
|
||||||
if (!clamAVService.scan(inputStream)) {
|
if (!clamAVService.scan(inputStream)) {
|
||||||
throw new StorageException("File rejected by antivirus scanner.");
|
throw new StorageException("File rejected by antivirus scanner.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset stream? MultipartFile.getInputStream() returns a new stream usually,
|
// Save to disk (Using transferTo which is safer than opening another stream)
|
||||||
// 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.createDirectories(destinationFile.getParent());
|
||||||
Files.copy(inputStream, destinationFile, StandardCopyOption.REPLACE_EXISTING);
|
file.transferTo(destinationFile.toFile());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class SlicerService {
|
|||||||
// File da processare (sempre per ultimo)
|
// File da processare (sempre per ultimo)
|
||||||
command.add(localStl.getAbsolutePath());
|
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);
|
runSlicerCommand(command, tempDir);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user