/**
  * respond with document if non json mime-type is requested
  *
  * @param Request $request Current http request
  * @param string  $id      id of file
  *
  * @return Response
  */
 public function getAction(Request $request, $id)
 {
     $accept = $request->headers->get('accept');
     if (substr(strtolower($accept), 0, 16) === 'application/json') {
         return parent::getAction($request, $id);
     }
     $response = $this->getResponse();
     if (!$this->gaufrette->has($id)) {
         $response->setStatusCode(Response::HTTP_NOT_FOUND);
         return $response;
     }
     $record = $this->findRecord($id);
     $data = $this->gaufrette->read($id);
     $response->setStatusCode(Response::HTTP_OK);
     $response->headers->set('Content-Type', $record->getMetadata()->getMime());
     return $this->render('GravitonFileBundle:File:index.raw.twig', ['data' => $data], $response);
 }
Beispiel #2
0
 /**
  * Reads the content from the file
  *
  * @param  string $key Key of the file
  *
  * @throws \Gaufrette\Exception\FileNotFound when file does not exist
  * @throws \RuntimeException                 when cannot read file
  *
  * @return string
  */
 public function read($key)
 {
     return $this->fileSystem->read($key);
 }