0

currently trying to serve a static PDF file that is not within the web directory ($reasons).

I applied

$filepath = $this->getTargetFile($level, $name);

$response = new BinaryFileResponse($filepath);
$response->headers->set('Content-Type', 'application/pdf');
$response->setContentDisposition(
    ResponseHeaderBag::DISPOSITION_INLINE,
    $filename
);
return $response;

and Profiler shows that there is a Response with correct headers, but there is no document view and no download prompt whatsoever. Is there something I am missing?

/** Get target file */
public function getTargetFile($level, $name)
{
    return $this->kernel->locateResource($staticPath . $level . '/' . $name);
}
Leon Willens
  • 356
  • 1
  • 16
  • the `$filepath` value is correct? – Matteo Nov 10 '16 at 11:27
  • `$filepath` was correct, yes. I think the problem was that there was no actual environment for the received data to be parsed into (i.e. no browser-based PDF reader), and in the end I had to override that manually via Javascript. – Leon Willens Nov 10 '16 at 14:56

1 Answers1

1

Some nerves were spent, but:

I created a form via JavaScript and submitted the needed parameters into a new window (thanks to this), that made the job. If anyone has a "cleaner" solution, I'm open to suggestions :)

Community
  • 1
  • 1
Leon Willens
  • 356
  • 1
  • 16