Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Since 2.0.0 missing mimeType on files uploaded #9

Closed
erodataM opened this issue Jul 5, 2019 · 5 comments
Closed

Since 2.0.0 missing mimeType on files uploaded #9

erodataM opened this issue Jul 5, 2019 · 5 comments

Comments

@erodataM
Copy link

erodataM commented Jul 5, 2019

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);

@arnouxor
Copy link

arnouxor commented Jul 8, 2019

We badly need that fix!

@pgmillon
Copy link
Member

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();
...

@AlexisGloux
Copy link

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.

@pgmillon
Copy link
Member

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:
image
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.

@pgmillon
Copy link
Member

Fixed with #14, backported with bf8f201 and released in https://github.com/nuxeo/nuxeo-php-client/releases/tag/2.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants