public function loadBlob($path, $contentType = 'application/binary') { try { $this->getBlobs()->add(Blob::fromFile($path, $contentType)); } catch (\Nuxeo\Client\Internals\Spi\NuxeoClientException $ex) { throw new NuxeoClientException($ex->getMessage()); } return parent::loadBlob($path, $contentType); }
/** * @param Response $response * @param string $clazz * @return mixed * @throws ClassCastException */ protected function computeResponse($response, $clazz) { if (false === ($response->isContentType(Constants::CONTENT_TYPE_JSON) || $response->isContentType(Constants::CONTENT_TYPE_JSON_NXENTITY))) { if (Blob::className !== $clazz) { throw new ClassCastException(sprintf('Cannot cast %s as %s', Blob::className, $clazz)); } return Blob::fromHttpResponse($response); } $body = $response->getBody(true); return $this->nuxeoClient->getConverter()->read($body, $clazz); }
$httpRequest = \Symfony\Component\HttpFoundation\Request::createFromGlobals(); $document = null; if ($httpRequest->files->has('blob') && $httpRequest->request->has('path')) { $path = $httpRequest->get('path'); $uploadedBlob = $httpRequest->files->get('blob'); /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $uploadedBlob */ $blob = $uploadedBlob->move($blobTempStorage, $uploadedBlob->getClientOriginalName()); try { /** @var \Nuxeo\Client\Api\Objects\Document $document */ $document = $client->automation('Document.Create')->input('doc:' . $path)->params(array('type' => 'File', 'name' => $blob->getFilename(), 'properties' => 'dc:title=' . $blob->getFilename()))->execute(\Nuxeo\Client\Api\Objects\Document::className); } catch (\Nuxeo\Client\Internals\Spi\NuxeoClientException $ex) { throw new RuntimeException(sprintf('Could not create Document %s: ' . $ex->getMessage(), $blob->getFilename())); } try { if (null !== $document) { $client->automation('Blob.Attach')->input(\Nuxeo\Client\Api\Objects\Blob::fromFile($blob->getPathname(), $blob->getMimeType()))->param('document', $document->getPath())->execute(\Nuxeo\Client\Api\Objects\Blob::className); } } catch (\Nuxeo\Client\Internals\Spi\NuxeoClientException $ex) { throw new RuntimeException('Could not attach blob to document: ' . $ex->getMessage()); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>B4 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">
public function testLoadBlob() { $client = new NuxeoClient($this->server->getUrl(), self::LOGIN, self::PASSWORD); $this->server->enqueue(array(new Response(200))); $client->automation('Blob.AttachOnDocument')->param('document', self::MYFILE_DOCPATH)->input(Blob::fromFile($this->getResource('user.json'), null))->execute(Blob::className); $requests = $this->server->getReceivedRequests(true); $this->assertCount(1, $requests); /** @var EntityEnclosingRequest $request */ $request = $requests[0]; $this->assertArrayHasKey('content-type', $request->getHeaders()); $this->assertStringMatchesFormat('multipart/related;boundary=%s', $request->getHeader('content-type')->__toString()); }