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);
}
2
  • the $filepath value is correct? Commented Nov 10, 2016 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. Commented Nov 10, 2016 at 14:56

1 Answer 1

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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.