@@ -57,25 +57,34 @@ class Processor
5757 */
5858 protected $ resourceModel ;
5959
60+ /**
61+ * @var \Magento\Framework\File\Mime
62+ */
63+ protected $ mime ;
64+
6065 /**
6166 * @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository
6267 * @param \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDb
6368 * @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig
6469 * @param \Magento\Framework\Filesystem $filesystem
6570 * @param \Magento\Catalog\Model\ResourceModel\Product\Gallery $resourceModel
71+ * @param \Magento\Framework\File\Mime $mime
72+ * @throws \Magento\Framework\Exception\FileSystemException
6673 */
6774 public function __construct (
6875 \Magento \Catalog \Api \ProductAttributeRepositoryInterface $ attributeRepository ,
6976 \Magento \MediaStorage \Helper \File \Storage \Database $ fileStorageDb ,
7077 \Magento \Catalog \Model \Product \Media \Config $ mediaConfig ,
7178 \Magento \Framework \Filesystem $ filesystem ,
72- \Magento \Catalog \Model \ResourceModel \Product \Gallery $ resourceModel
79+ \Magento \Catalog \Model \ResourceModel \Product \Gallery $ resourceModel ,
80+ \Magento \Framework \File \Mime $ mime
7381 ) {
7482 $ this ->attributeRepository = $ attributeRepository ;
7583 $ this ->fileStorageDb = $ fileStorageDb ;
7684 $ this ->mediaConfig = $ mediaConfig ;
7785 $ this ->mediaDirectory = $ filesystem ->getDirectoryWrite (DirectoryList::MEDIA );
7886 $ this ->resourceModel = $ resourceModel ;
87+ $ this ->mime = $ mime ;
7988 }
8089
8190 /**
@@ -186,10 +195,10 @@ public function addImage(
186195 $ position = 0 ;
187196
188197 $ absoluteFilePath = $ this ->mediaDirectory ->getAbsolutePath ($ file );
189- $ imageMimeType = mime_content_type ($ absoluteFilePath );
190- $ imageContent = file_get_contents ($ absoluteFilePath );
198+ $ imageMimeType = $ this -> mime -> getMimeType ($ absoluteFilePath );
199+ $ imageContent = $ this -> mediaDirectory -> readFile ($ absoluteFilePath );
191200 $ imageBase64 = base64_encode ($ imageContent );
192- $ imageName = pathinfo ( $ destinationFile , PATHINFO_FILENAME ) ;
201+ $ imageName = $ pathinfo [ ' filename ' ] ;
193202
194203 if (!is_array ($ mediaGalleryData )) {
195204 $ mediaGalleryData = ['images ' => []];
@@ -203,17 +212,17 @@ public function addImage(
203212
204213 $ position ++;
205214 $ mediaGalleryData ['images ' ][] = [
206- 'file ' => $ fileName ,
207- 'position ' => $ position ,
208- 'label ' => '' ,
209- 'disabled ' => (int )$ exclude ,
215+ 'file ' => $ fileName ,
216+ 'position ' => $ position ,
217+ 'label ' => '' ,
218+ 'disabled ' => (int )$ exclude ,
210219 'media_type ' => 'image ' ,
211- 'types ' => $ mediaAttribute ,
212- 'content ' => [
220+ 'types ' => $ mediaAttribute ,
221+ 'content ' => [
213222 'data ' => [
214- ImageContentInterface::NAME => $ imageName ,
223+ ImageContentInterface::NAME => $ imageName ,
215224 ImageContentInterface::BASE64_ENCODED_DATA => $ imageBase64 ,
216- ImageContentInterface::TYPE => $ imageMimeType ,
225+ ImageContentInterface::TYPE => $ imageMimeType ,
217226 ]
218227 ]
219228 ];
0 commit comments