public function uploadMedia(Media $media, $acl = 'public-read')
 {
     $targetPath = parse_url($media->getUrl(), PHP_URL_PATH);
     if ($media->getUrl() === $targetPath) {
         throw new \InvalidArgumentException('Media has to have a public URL set before uploading');
     }
     if (null === $media->getContent()) {
         throw new \RuntimeException('Dunno how to get file contents');
     }
     $fd = fopen($media->getContent()->getRealPath(), 'rb');
     $storageResponse = $this->storage->putObject(['ACL' => $acl, 'Bucket' => $this->bucketName, 'Key' => ltrim($targetPath, '/'), 'Body' => $fd, 'ContentType' => $media->getContentType(), 'CacheControl' => 'public, max-age=283824000', 'Expires' => gmdate('D, d M Y H:i:s T', strtotime('+9 years'))]);
     fclose($fd);
     return $storageResponse->get('ObjectURL');
 }
 private function validateMimeType(MediaObject $value, $allowedMimeTypes)
 {
     $mimeType = strtolower($value->getContentType());
     foreach ($allowedMimeTypes as $type) {
         $type = strtolower($type);
         if ($type === $mimeType) {
             return true;
         }
         if ($discrete = strstr($type, '/*', true)) {
             if (strstr($mimeType, '/', true) === $discrete) {
                 return true;
             }
         }
     }
     return false;
 }
 /**
  * @param Media $media
  *
  * @return \Gaufrette\File
  */
 public function getOriginalFile(Media $media)
 {
     $relativePath = sprintf('/%s.%s', $media->getUuid(), ExtensionGuesser::getInstance()->guess($media->getContentType()));
     return $this->fileSystem->get($relativePath, true);
 }
Esempio n. 4
0
 /**
  * @covers Kunstmaan\MediaBundle\Entity\Media::getContentType
  * @covers Kunstmaan\MediaBundle\Entity\Media::getContentTypeShort
  * @covers Kunstmaan\MediaBundle\Entity\Media::setContentType
  */
 public function testGetSetContentType()
 {
     $this->object->setContentType('image/jpeg');
     $this->assertEquals('image/jpeg', $this->object->getContentType());
     $this->assertEquals('jpeg', $this->object->getContentTypeShort());
 }