/** * @Route( * "/attachment/download/comment/{commentId}/attachment/{attachId}", * name="diamante_ticket_comment_attachment_download", * requirements={"commentId"="\d+", "attachId"="\d+"} * ) * @return Response * @todo move to application service */ public function downloadAttachmentAction($commentId, $attachId) { /** @var CommentService $commentService */ $commentService = $this->get('diamante.comment.service'); $retrieveCommentAttachment = new RetrieveCommentAttachmentCommand(); $retrieveCommentAttachment->attachmentId = $attachId; $retrieveCommentAttachment->commentId = $commentId; $attachment = $commentService->getCommentAttachment($retrieveCommentAttachment); $filename = $attachment->getFilename(); $filePathname = realpath($this->container->getParameter('kernel.root_dir') . '/attachments/comment') . '/' . $attachment->getFilename(); if (!file_exists($filePathname)) { $this->addErrorMessage('diamante.desk.attachment.messages.get.error'); throw $this->createNotFoundException('Attachment not found'); } $response = new \Symfony\Component\HttpFoundation\BinaryFileResponse($filePathname); $response->trustXSendfileTypeHeader(); $response->setContentDisposition(\Symfony\Component\HttpFoundation\ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename)); return $response; }
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Contributors: * Pierre-Gildas MILLON <*****@*****.**> */ require_once '../vendor/autoload.php'; $client = new \Nuxeo\Client\Api\NuxeoClient('http://nuxeo:8080/nuxeo', 'Administrator', 'Administrator'); if (!empty($_POST['path'])) { $path = $_POST['path']; try { /** @var \Nuxeo\Client\Api\Objects\Blob $blob */ $blob = $client->automation('Blob.Get')->input('doc:' . $path)->execute(\Nuxeo\Client\Api\Objects\Blob::className); $response = new \Symfony\Component\HttpFoundation\BinaryFileResponse($blob->getFile()); $response->setContentDisposition(\Symfony\Component\HttpFoundation\ResponseHeaderBag::DISPOSITION_ATTACHMENT, $blob->getFilename()); $response->prepare(\Symfony\Component\HttpFoundation\Request::createFromGlobals())->send(); } catch (\Nuxeo\Client\Internals\Spi\NuxeoClientException $ex) { throw new RuntimeException(sprintf('Could not fetch blob of %s: ', $path) . $ex->getMessage()); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>B5 test php Client</title> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">