src/Graviton/FileBundle/Manager/FileManager.php
public function buildGetContentResponse(Response $response, FileDocument $file)
    {
        /** @var FileMetadataBase $metadata */
        $metadata = $file->getMetadata();
        if (!$metadata) {
            throw new InvalidArgumentException('Loaded file have no valid metadata');
        }

        // We use file's mimeType, just in case none we use DB's.
        $mimeType = null;

        if ($this->readFileSystemMimeType) {
            $mimeType = $this->fileSystem->getMimetype($file->getId());
        }
        if (!$mimeType) {
            $mimeType = $metadata->getMime();
        }
        if ($this->allowedMimeTypes && !in_array($mimeType, $this->allowedMimeTypes)) {
            throw new InvalidArgumentException('File mime type: '.$mimeType.' is not allowed as response.');
        }

        // Create Response
        $disposition = $response->headers->makeDisposition(
            ResponseHeaderBag::DISPOSITION_INLINE,
            $metadata->getFilename()
        );

        $response
            ->setStatusCode(Response::HTTP_OK)
            ->setContent($this->fileSystem->read($file->getId()));
        $response
            ->headers->set('Content-Type', $mimeType);
        $response
            ->headers->set('Content-Disposition', $disposition);
        return $response;
    }
public function buildGetContentResponse(Response $response, FileDocument $file)
    {
        /** @var FileMetadataBase $metadata */
        $metadata = $file->getMetadata();
        if (!$metadata) {
            throw new InvalidArgumentException('Loaded file have no valid metadata');
        }

        // We use file's mimeType, just in case none we use DB's.
        $mimeType = null;

        if ($this->readFileSystemMimeType) {
            $mimeType = $this->fileSystem->getMimetype($file->getId());
        }
        if (!$mimeType) {
            $mimeType = $metadata->getMime();
        }
        if ($this->allowedMimeTypes && !in_array($mimeType, $this->allowedMimeTypes)) {
            throw new InvalidArgumentException('File mime type: '.$mimeType.' is not allowed as response.');
        }

        // Create Response
        $disposition = $response->headers->makeDisposition(
            ResponseHeaderBag::DISPOSITION_INLINE,
            $metadata->getFilename()
        );

        $response
            ->setStatusCode(Response::HTTP_OK)
            ->setContent($this->fileSystem->read($file->getId()));
        $response
            ->headers->set('Content-Type', $mimeType);
        $response
            ->headers->set('Content-Disposition', $disposition);
        return $response;
    }
public function buildGetContentResponse ( Response $ response , FileDocument $ file ) { /** @var FileMetadataBase $metadata */ $ metadata = $ file -> getMetadata ( ) ; if ( ! $ metadata ) { throw new InvalidArgumentException ( 'Loaded file have no valid metadata' ) ; } // We use file's mimeType, just in case none we use DB's. $ mimeType = null ; if ( $ this -> readFileSystemMimeType ) { $ mimeType = $ this -> fileSystem -> getMimetype ( $ file -> getId ( ) ) ; } if ( ! $ mimeType ) { $ mimeType = $ metadata -> getMime ( ) ; } if ( $ this -> allowedMimeTypes && ! in_array ( $ mimeType , $ this -> allowedMimeTypes ) ) { throw new InvalidArgumentException ( 'File mime type: ' . $ mimeType . ' is not allowed as response.' ) ; } // Create Response $ disposition = $ response -> headers -> makeDisposition ( ResponseHeaderBag :: DISPOSITION_INLINE , $ metadata -> getFilename ( ) ) ; $ response -> setStatusCode ( Response :: HTTP_OK ) -> setContent ( $ this -> fileSystem -> read ( $ file -> getId ( ) ) ) ; $ response -> headers -> set ( 'Content-Type' , $ mimeType ) ; $ response -> headers -> set ( 'Content-Disposition' , $ disposition ) ; return $ response ; }
Will update the response object with provided file data

@param Response     $response response
@param DocumentFile $file     File document object from DB

@return Response
@throws InvalidArgumentException if invalid info fetched from fileSystem
Will update the response object with provided file data