예제 #1
0
 function download_nuxeo_document()
 {
     $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
     $validation = \Symfony\Component\Validator\Validation::createValidator();
     $nxsession = $this->getClient();
     if ($request->query->has('nx_doc_id')) {
         $doc_id = $request->query->get('nx_doc_id');
         $violations = $validation->validate($doc_id, array(new \Symfony\Component\Validator\Constraints\Uuid()));
         if (0 === count($violations)) {
             $doc = $nxsession->newRequest("Document.Fetch")->set('params', 'value', $doc_id)->setSchema($schema = 'dublincore,file')->sendRequest()->getDocument(0);
             try {
                 $file_content = $nxsession->newRequest("Blob.Get")->set('input', 'doc:' . $doc_id)->sendRequest();
                 $file_info = new AttributesBag($doc->getProperty('file:content'));
                 $response = new \Symfony\Component\HttpFoundation\Response($file_content);
                 $response->setLastModified(new DateTime($doc->getProperty('dc:modified')));
                 $response->headers->add(array('Content-Disposition' => $response->headers->makeDisposition(\Symfony\Component\HttpFoundation\ResponseHeaderBag::DISPOSITION_ATTACHMENT, $doc->getProperty('file:filename')), 'Content-Length' => $file_info->offsetGet('length'), 'Content-Type' => $file_info->offsetGet('mime-type', 'application/octet-stream')));
             } catch (Exception $e) {
                 $response = new \Symfony\Component\HttpFoundation\Response($e->getMessage());
             }
             $response->send();
             exit;
         }
     }
 }