I am trying to download a file (Attachment here) from Controller
Here is my code:
public function downloadFiletAction(Request $request, Attachment $attachment) { $mountManager = $this->get('oneup_flysystem.mount_manager'); $fileSystem = $mountManager->getFilesystem('faq'); return new BinaryFileResponse($fileSystem->getAdapter()->getPathPrefix() . $attachment->getFilename()); }
This code:
$fileSystem->getAdapter()->getPathPrefix() . $attachment->getFilename()
returns the absolute path (which is correct)
Finally, I get this error => Content cannot be set in an instance of BinaryFileResponse.
It looks like when I create a BinaryFileResponse, symfony puts its contents in NULL (this is what I want), but when I put the return statement. my content is replaced with an empty string, which is bad because the next BinaryFileResponse function throws an exception.
public function setContent($content) { if (null !== $content) { throw new \LogicException('The content cannot be set on a BinaryFileResponse instance.'); } }
Also, if I delete the if statement in the setContent method, everything works like a charm. (but this is not the best thing)
thanks for the help
Jaybe source share