Closed erodataM closed 3 years ago
We badly need that fix!
Hi, I'm sorry I couldn't work on this project since a while. I spent some time trying to reproduce the issue without luck so far. I guess you're using the client v2.0.0 but can you share the Nuxeo Platform version (8.10, 9.10, ...) and a code excerpt ?
I modified the ftests to upload a PDF on a stock NXP-9.10 and have no issues (original FT):
...
$this->getClient()
->automation('Blob.Attach')
->param('document', $doc->getPath())
->input(Blob::fromFile($this->getResource('lipsum.pdf'), null))
->execute();
...
Hi, I work with Ludoutt who contacted you this week. Our version of Nuxeo is 9.10-01 and we attach a file like this:
$fileBlob = Blob::fromFile($file['file']['tmp_name'], $file['file']['type']);
$this->client->automation('Blob.AttachOnDocument')
->param('document', $nuxeoDocument->getUid())
->input($fileBlob)
->execute(Blob::class);
Thanks for your help.
I finally managed to reproduce your issue.
The root cause is the tmp file uploaded on the server that has a generated name (expected). Obviously, Nuxeo cannot detect the file type from the file name, so you end up with a binary file with no preview: Correct me if I'm wrong, but that's probably the behavior you're experiencing.
A quick fix would be to move the tmp file back with it's original name. That's what I'm doing in the B4 sample. It only mitigates the issue but has 2 benefits: the preview works fine because Nuxeo detection works back, and you have an attachment with a correct file name rather than keep the generated name. I also strongly recommend you don't mess with $_FILES but use some wrapper around them (I used symfony/http-foundation that does a pretty nice job IMHO), but that's just my 20 cents.
I'm working on fixing the issue based on @fherbin work. I'll release it under both a minor with additional features and bugfix so you can have it faster.
Fixed with #14, backported with https://github.com/nuxeo/nuxeo-php-client/commit/bf8f201840f59fabe802b7a0de77ce32248b95bf and released in https://github.com/nuxeo/nuxeo-php-client/releases/tag/2.0.1
For example if we upload a PDF file, there is no preview on nuxeo platform.
We have a potential fix : nuxeo-php-client\src\Nuxeo\Client\Spi\Objects\NuxeoEntity.php (line 125 : method getResponseNew())
$request = $request->addRelatedFile($file, $file->getContentType());
instead of :$request = $request->addRelatedFile($file);