1616use Magento \Framework \Filesystem \Driver \Https ;
1717use Magento \Framework \Filesystem \DriverInterface ;
1818use Magento \MediaGalleryApi \Api \IsPathExcludedInterface ;
19- use Magento \Framework \Exception \InputException ;
2019
2120/**
2221 * Save images to the file system
@@ -41,23 +40,23 @@ class Save
4140 private $ isPathExcluded ;
4241
4342 /**
44- * @var Int
43+ * @var int|null
4544 */
4645 private $ maxFileLength ;
4746
4847 /**
4948 * @param Filesystem $filesystem
5049 * @param Https $driver
5150 * @param IsPathExcludedInterface $isPathExcluded
52- * @param Int $maxFileLength
51+ * @param int|null $maxFileLength
5352 */
5453 public function __construct (
5554 Filesystem $ filesystem ,
5655 Https $ driver ,
5756 IsPathExcludedInterface $ isPathExcluded ,
58- $ maxFileLength
57+ int $ maxFileLength = null
5958 ) {
60- $ this ->maxFileLength = $ maxFileLength ;
59+ $ this ->maxFileLength = $ maxFileLength ?: 255 ;
6160 $ this ->filesystem = $ filesystem ;
6261 $ this ->driver = $ driver ;
6362 $ this ->isPathExcluded = $ isPathExcluded ;
@@ -72,12 +71,11 @@ public function __construct(
7271 * @throws AlreadyExistsException
7372 * @throws FileSystemException
7473 * @throws LocalizedException
75- * @throws InputException
7674 */
7775 public function execute (string $ imageUrl , string $ destinationPath , bool $ allowOverwrite = false ): void
7876 {
7977 if (strlen ($ destinationPath ) > $ this ->maxFileLength ) {
80- throw new InputException (
78+ throw new LocalizedException (
8179 __ ('Destination path is too long; must be %1 characters or less ' , $ this ->maxFileLength )
8280 );
8381 }
0 commit comments