denyAccessUnlessGranted('read', $attachment); if ($attachment->isExternal()) { throw new \RuntimeException('You can not download external attachments!'); } if (!$helper->isFileExisting($attachment)) { throw new \RuntimeException('The file associated with the attachment is not existing!'); } $file_path = $helper->toAbsoluteFilePath($attachment); $response = new BinaryFileResponse($file_path); //Set header content disposition, so that the file will be downloaded $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT); return $response; } /** * View the attachment * * @Route("/attachment/{id}/view", name="attachment_view") * @param Attachment $attachment * @param AttachmentManager $helper * @return BinaryFileResponse * @throws \Exception */ public function view(Attachment $attachment, AttachmentManager $helper) { $this->denyAccessUnlessGranted('read', $attachment); if ($attachment->isExternal()) { throw new \RuntimeException('You can not download external attachments!'); } if (!$helper->isFileExisting($attachment)) { throw new \RuntimeException('The file associated with the attachment is not existing!'); } $file_path = $helper->toAbsoluteFilePath($attachment); $response = new BinaryFileResponse($file_path); //Set header content disposition, so that the file will be downloaded $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE); return $response; } /** * @Route("/attachment/list", name="attachment_list") * @param DataTableFactory $dataTable * @param Request $request * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response */ public function attachmentsTable(DataTableFactory $dataTable, Request $request) { $this->denyAccessUnlessGranted('read', new PartAttachment()); $table = $dataTable->createFromType(AttachmentDataTable::class) ->handleRequest($request); if ($table->isCallback()) { return $table->getResponse(); } return $this->render('attachment_list.html.twig', [ 'datatable' => $table ]); } }