PartKeepr\UploadedFileBundle\Controller\FileController::getFileAction PHP Méthode

getFileAction() public méthode

Returns the file. Directly sends the response to the browser.
public getFileAction ( integer $id ) : Response
$id integer The ID of the file
Résultat Symfony\Component\HttpFoundation\Response
    public function getFileAction($id)
    {
        /**
         * @var EntityManager
         */
        $em = $this->getDoctrine()->getManager();
        /**
         * @var UploadedFile
         */
        $file = $em->find($this->getEntityClass(), $id);
        $storage = $this->get('partkeepr_uploadedfile_service')->getStorage($file);
        try {
            return new Response($storage->read($file->getFullFilename()), 200, ['Content-Type' => $file->getMimeType()]);
        } catch (FileNotFound $e) {
            $this->get('logger')->addError(sprintf('File %s not found in storage %s', $file->getFullFilename(), $file->getType()));
            return new Response('404 File not found', 404);
        }
    }