/**
  * @param  array                                                          $drupalProduct
  * @param  ProductValue                                                   $productValue
  * @param  string                                                         $field
  * @param  array                                                          $context
  * @throws \Pim\Bundle\CatalogBundle\Exception\MissingIdentifierException
  */
 public function normalize(array &$drupalProduct, $productValue, $field, array $context = array())
 {
     $media = $productValue->getMedia();
     if ($media && null !== $media->getFilename()) {
         $drupalProduct['values'][$field][$context['locale']][] = ['type' => 'pim_catalog_image', 'filename_original' => $media->getOriginalFilename(), 'filename' => $media->getFilename(), 'mimetype' => $media->getMimeType(), 'length' => filesize($this->mediaManager->getFilePath($media)), 'absolute_path' => $this->mediaManager->getFilePath($media), 'attribute_id' => $media->getValue()->getAttribute()->getId(), 'media_id' => $media->getId(), 'rest_url' => '/api/rest/media/' . $productValue->getEntity()->getIdentifier() . '/' . $productValue->getAttribute()->getId()];
     }
 }
 /**
  * @param  ProductValue $productValue
  * @param $attribute
  * @return string
  */
 public function getSerializedData(ProductValue $productValue, $attribute)
 {
     /** @var ProductMedia $media */
     $media = $productValue->getMedia();
     /** @var MediaManager $mediaManager */
     $mediaManager = $this->get('pim_catalog.manager.media');
     /** @var ProductValue $productValue */
     $info_media = new \stdClass();
     $info_media->content = $mediaManager->getBase64($media);
     $info_media->created = $productValue->getAttribute()->getCreated()->getTimestamp();
     $info_media->updated = $productValue->getAttribute()->getUpdated()->getTimestamp();
     $info_media->filename = $media->getFilename();
     $info_media->filepath = $media->getFilePath();
     $info_media->originalFilename = $media->getOriginalFilename();
     $info_media->mimeType = $media->getMimeType();
     $info_media->size = filesize($media->getFilePath());
     $data = json_encode($info_media);
     return $data;
 }
 /**
  * {@inheritDoc}
  */
 public function getMedia()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getMedia', array());
     return parent::getMedia();
 }