Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Adding possibility to add custom MimeTypeGuesser in configuration #28832

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

Closed
ludovig opened this issue Oct 12, 2018 · 1 comment
Closed

Adding possibility to add custom MimeTypeGuesser in configuration #28832

ludovig opened this issue Oct 12, 2018 · 1 comment

Comments

@ludovig
Copy link

ludovig commented Oct 12, 2018

Hello,

I'm currently working for a french retailer and we had an issue with some pdf uploads.
Those pdf (Orange invoices used as address proof), are recognized as application/octet-stream by file -b -mime and finfo_open.
So we used pdfinfo from popplers project to identify it as pdf.

However we have two problems with current implementation.

Do you have any idea on how to improve on this ?
Adding some configuration possibility was what we tought of, but maybe there is other ways to get a more optimal solution to get some generated pdf used as official document to be accepted as pdf.

Thanks for your help

@nCrazed
Copy link

nCrazed commented Oct 15, 2018

This command pdfinfo, is called for every uploaded file, not only pdf one, as an array_unshift put our custom guesser as the preferred one.

You could work around this by re-adding existing (or just the important) guessers after your custom ones as described here: https://api.symfony.com/master/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.html

Alternatively, I think, it should be possible to conditionally register your guesser either in the route handler just before validation, or if necessary, via an event listener that runs after route resolution (or whatever other step is important for determining the relevance of the request), but before your validation.

@fabpot fabpot closed this as completed Jan 17, 2019
fabpot added a commit that referenced this issue Jan 17, 2019
This PR was squashed before being merged into the 4.3-dev branch (closes #29896).

Discussion
----------

[Mime] Add the component

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #28832 #21985 makes #15460 trivial
| License       | MIT
| Doc PR        | symfony/symfony-docs#10886

This has been on my todo-list for X years :)

Commits
-------

bdca5d9 tweaked code
5268389 [Mime] added freedesktop as a source for mime types
74ca91d [Mime] added the component
d7ee0ec [HttpFoundation] updated File code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants