@@ -47,19 +47,22 @@ public StorageServiceImpl(@Value("${app.storage.base-path}") Path basePath) thro
4747 * @param relativeFileName the relative name of the file to save.
4848 * @param content the content of the file as a byte array.
4949 * @return the path to the saved file.
50- * @throws StorageSecurityException if the file name is invalid or attempts to escape the storage directory.
50+ * @throws StorageSecurityException if an attempt is made to escape the storage directory.
5151 * @throws StorageException if an error occurs during file operations.
52- * @throws IOException if an I/O error occurs.
5352 */
5453 @ Override
55- public Path save (String relativeFileName , byte [] content ) throws StorageSecurityException , StorageException , IOException {
54+ public Path save (String relativeFileName , byte [] content ) throws StorageSecurityException , StorageException {
5655 log .debug ("Saving file: {} ({} bytes)" , relativeFileName , content .length );
5756
58- var targetPath = safeResolve (relativeFileName );
59- Files .createDirectories (targetPath .getParent ());
60- Files .write (targetPath , content , StandardOpenOption .CREATE , StandardOpenOption .TRUNCATE_EXISTING );
61- log .debug ("Saved file: {} ({} bytes)" , targetPath , content .length );
62- return targetPath ;
57+ try {
58+ var targetPath = safeResolve (relativeFileName );
59+ Files .createDirectories (targetPath .getParent ());
60+ Files .write (targetPath , content , StandardOpenOption .CREATE , StandardOpenOption .TRUNCATE_EXISTING );
61+ log .debug ("Saved file: {} ({} bytes)" , targetPath , content .length );
62+ return targetPath ;
63+ } catch (IOException e ) {
64+ throw new StorageException ("Failed to store file " + relativeFileName , e );
65+ }
6366 }
6467
6568 /**
0 commit comments