Download a media file.

@param string $fileId

@return Response
@Route("/download/{fileId}", name="frontendmedia_download")
961988
public function downloadAction($fileId)
    {
        $volumeManager = $this->get('phlexible_media_manager.volume_manager');

        try {
            $volume = $volumeManager->getByFileId($fileId);
        } catch (\Exception $e) {
            throw $this->createNotFoundException($e->getMessage(), $e);
        }

        // TODO get lates file version
        $file = $volume->findFile($fileId);

        $filePath = $file->getPhysicalPath();

        if (!file_exists($filePath)) {
            throw $this->createNotFoundException('File not found.');
        }

        $mimeType = $file->getMimeType();

        $response = new BinaryFileResponse($filePath, 200, array('Content-Type' => $mimeType));
        $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $file->getName());

        return $response;
    }
945677
public function privateDownloadUrl($publicId, $format, $options = array())
    {
        return $this->getCloudinary()->private_download_url($publicId, $format, $options);
    }
1099441
public function downloadMedia($mediaId, $filePath)
    {
        $url    = $this->getMediaUrl($mediaId);
        $client = $this->getHttpClient();
        $client->setUrl($url);
        if (!$client->exec()) {
            throw new Exception("call download Media fail");
        }

        return $this->getFileSystem()->put($filePath, $client->getResponse()) > 0;
    }
990968
public static DownloadResponse exportFile(Drive drive, String fileId, String format) throws IOException {
    try (InputStream inputStream = drive.files().export(fileId, format).executeAsInputStream()) {
      return new DownloadResponse(format, IOUtils.toByteArray(inputStream));
    }
  }
1017218
private function getVideo($videoId)
    {
        if (!array_key_exists($videoId, $this->videos)) {
            $options = new VideoRequestParameters();
            $options->setIncludeCustomMetadata(true);
            $this->videos[$videoId] = $this->client->getVideo($this->vmId, $videoId, $options);
        }

        return $this->videos[$videoId];
    }
819517
public function delete($mediaId)
    {
        return Response::json($this->curl->post(self::DELETE.$this->access_token, json_encode([
                    'media_id' => $mediaId,
                ]
            )
        )
        );
    }
571822
public function uploadAction($folderId, Request $request)
    {
        $uploadedFile = $request->files->get('file');
        $title = $request->get('title');

        $saveMediaManager = $this->get('open_orchestra_media_admin.manager.save_media');

        if ($uploadedFile && $uploadedFile = $saveMediaManager->getFileFromChunks($uploadedFile)) {
            $siteId = $this->get('open_orchestra_backoffice.context_backoffice_manager')->getSiteId();
            $media = $saveMediaManager->initializeMediaFromUploadedFile($uploadedFile, $folderId, $siteId, $title);
            $violations = $this->get('validator')->validate($media, null, array('upload'));
            if (count($violations) !== 0) {
                return new Response(
                    implode('.', $this->getViolationsMessage($violations)),
                    403
                );
            }

            $saveMediaManager->saveMedia($media);

            return $this->get('open_orchestra_api.transformer_manager')->transform('media', $media);

        }

        return new Response('', 202);
    }
1025810
public function downloadAction(string $path): Response
    {
        if (!$meta = $this->filesystem->getMetadata($path)) {
            throw new NotFoundHttpException('Media not found: ' . $path);
        }

        $content = $this->filesystem->read($path);

        $response = new Response($content);
        $response->headers->set('Content-Type', $meta['mimetype']);
        $response->headers->set('Content-Length', $meta['size']);
        $response->headers->set('Content-Transfer-Encoding', 'binary');

        $name = explode('/', $path);

        $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $name[count($name) - 1]);
        $response->headers->set('Content-Disposition', $disposition);

        return $response;
    }
273944
public function removeAction($fileId = null)
    {
        if (!$fileId) {
            return new Response('Please provide a file id', 500);
        }

        $manager = $this->getDoctrine()->getManager();
        $repo = $this->getDoctrine()->getRepository('LibrinfoMediaBundle:File');

        $file = $repo->findOneBy([
            'id'    => $fileId,
        ]);

        if ($file !== null) {
            if ($file->isOwned()) {
                $dispatcher = $this->get('event_dispatcher');
                $event = new GenericEvent($file);
                $dispatcher->dispatch(UploadControllerEventListener::REMOVE_ENTITY, $event);
            }

            $name = '' . $file->getName();
            $manager->remove($file);
            $manager->flush();

            return new Response($name . ' removed successfully', 200);
        } else {
            return new Response('the file cannot be removed', 401);
        }
    }
62220
public function get($mediaId)
    {
        $node     = 'get';
        $queryStr = ['media_id' => $mediaId];

        $res = $this->_get($node, $queryStr);

        return $res;
    }
988436
public function downloadAction($storageId)
    {
        $fileManager = $this->get('beaast.core.manager.file');

        /**
         * @var File $file
         */
        $file = $fileManager->findOneBy(['storageId' => $storageId]);

        if (!$file) {
            throw $this->createNotFoundException();
        }

        $filePath = $fileManager->getFilePath($file);

        return new BinaryFileResponse($filePath, 200, [
            'Cache-Control'     => 'private',
            'Content-Type'     => $file->getMimeType(),
            'Content-length'     => $file->getSize(),
            'Content-Disposition' => 'attachment; filename="'.$file->getFileName().'"',
        ]);
    }
279223
public function fileAction($storageId)
    {
        $fileManager = $this->get('beaast.core.manager.file');

        /**
         * @var File $file
         */
        $file = $fileManager->findOneBy(['storageId' => $storageId]);

        if (!$file) {
            return new Response('File not found.', 404);
        }

        $filePath = $fileManager->getFilePath($file);

        $headers = array();
        if ($file->getExtension() === 'png') {
            $headers = array(
                'Content-Type'     => 'image/png',
                'Content-Disposition' => 'inline; filename="'.$file->getFileName().'"',
            );
        } elseif ($file->getExtension() === 'jpg') {
            $headers = array(
                'Content-Type'     => 'image/jpg',
                'Content-Disposition' => 'inline; filename="'.$file->getFileName().'"',
            );
        } elseif ($file->getExtension() === 'pdf' || $file->getExtension() === 'xlsx') {
            $headers = array(
                'Cache-Control'     => 'private',
                'Content-Type'     => $file->getMimeType(),
                'Content-length'     => $file->getSize(),
                'Content-Disposition' => 'attachment; filename="'.$file->getFileName().'"',
            );
        }

        return new Response(file_get_contents($filePath), 200, $headers);
    }
944957
def download(self, media_id, as_stream=False):
        
        response = self.__app.native_api_call('media', 'd/' + media_id, {}, self.__options, False, None, as_stream, http_path="/api/meta/v1/", http_method='GET')
        return response
1163476
public function downloadMediaAction($filename)
    {
        $media = $this->mediaManager->getRepository()->findOneByReference($filename);
        $provider = $this->container->get('opifer.media.provider.pool')->getProvider($media->getProvider());

        $mediaUrl = $provider->getUrl($media);

        $fileSystem = $provider->getFileSystem();
        $file = $fileSystem->read($media->getReference());
        
        $response = new Response();
        $response->headers->set('Content-type', $media->getContentType());
        $response->headers->set('Content-Disposition', sprintf('attachment; filename="%s"', basename($mediaUrl)));
        $response->setContent($file);
        
        return $response;
    }
759009
public function downloadAction(Request $request)
    {
        /**
         * @var \Ekyna\Bundle\MediaBundle\Model\MediaInterface $media
         * @var \League\Flysystem\File $file
         */
        list($media, $file) = $this->findMedia($request->attributes->get('key'));

        $lastModified = $media->getUpdatedAt();

        $response = new Response();
        $response->setPublic();
        $response->setLastModified($lastModified);
        $response->setEtag(md5($file->getPath().$lastModified->getTimestamp()));
        if ($response->isNotModified($request)) {
            return $response;
        }

        $response = new StreamedResponse();
        $response->setPublic();
        $response->setLastModified($lastModified);
        $response->setEtag(md5($file->getPath().$lastModified->getTimestamp()));

        // Set the headers
        $response->headers->set('Content-Type', $file->getMimetype());
        $response->headers->set('Content-Length', $file->getSize());

        $response->setCallback(function () use ($file) {
            fpassthru($file->readStream());
        });

        return $response;
    }
733563
public function downloadMedia($mediaId)
    {
        $result = $this->_curl("https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token={$this->getAccessToken()}&media_id={$mediaId}");

        $match = [];

        preg_match_all('/\nContent-disposition: ?attachment; ?filename="([^"]*?)"/ism', $result['head'], $match);

        return [
            'filename' => $match[1][0],
            'content' => $result['body'],
        ];
    }
1338332
public static DownloadResponse downloadFile(Drive drive, String fileId) throws IOException {
	  Get request = drive.files().get(fileId).setAlt("media");
	  String contentType = request.executeUsingHead().getContentType();
	  if (StringUtils.isNotBlank(contentType)) {
  	  try (InputStream inputStream = request.executeAsInputStream()) {
	      return new DownloadResponse(contentType, IOUtils.toByteArray(inputStream));
      }
	  }
	  
	  return null;
	}