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);
    }
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);
    }
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 ) ; }
Get the storage file

@param string $storageId

@return Response A Response instance
Get the storage file