-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
[13.0][FIX] dms: dms.file thumbnail generation checks for supported mimetypes #236
Conversation
c109020
to
f957174
Compare
The pre-commit error seems unrelated to my PR. Unsure how to fix it... |
I think we should instead restrict the mimetypes to the ones supported. |
And next time, it's better to only propose the PR for one branch, and wait until the feedback and being merged for not having to modify 3 PRs at the same time (although thank you very much for caring about all the versions 😃) |
I'll try to find that out and implement it. Thanks for the feedback |
Having a fair amount of trouble finding any sort of exhaustive list of mimetypes pillow supports. I think the best I can do is to start with a conservative list of image types that are for sure supported and then maybe it can be expanded in the future. (I also don't necessarily have all these files using different extensions at hand to easily test the PR with) |
Ok, then maybe the try/except approach is better having that uncertainty. My only fear was the memory consumption, as for example DWG files are usually very heavy. |
I'm seeing that you can query the supported mimetypes seeing if included in |
I agree. Maybe a size limit could work instead? Don't try to generate a thumbnail if the image is bigger than 20MB? |
I'll check that out. |
f957174
to
584b4f5
Compare
The list of mimetypes in the registry is surprisingly small. In Odoo shell on v13, python 3.6 and Pillow 5.4.1:
Thanks a lot for the pointers, by the way! |
584b4f5
to
82c0c68
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see... The advantage of this method is that if PIL evolves for further formats, we will be covered without doing any change in our code.
I would bet that latest versions have support for WEBP and other formats.
@victoralmau can you check about pre-commit in other PR? |
I'm wondering now what happens with SVG files. Have you checked them? |
(Sorry, didn't have time to look at this this week, will pick it back up asap) |
You can rebase now to have green CI. Please check the SVG part. |
82c0c68
to
ddf945c
Compare
I can confirm that if you upload an SVG file, the preview is not automatically generated. However, SVG files do work if they're used manually on the image_1920 field. Whereas, with a .png file, the preview is automatically set when uploading the file itself. Clearly, |
Well, I think we can start this with such list + SVG manually added to the supported ones. |
This PR has the |
The method _compute_image_1920 of dms_file checks if the file is of mimetype image and tries to use it as a thumbnail. However, there are several types of image files that Odoo/PIL cannot work with, leading to the following error: ``` Traceback (most recent call last): File "/opt/odoo/custom/src/odoo/odoo/tools/image.py", line 404, in base64_to_image return Image.open(io.BytesIO(base64.b64decode(base64_source))) File "/usr/local/lib/python3.6/site-packages/PIL/Image.py", line 2687, in open % (filename if filename else fp)) OSError: cannot identify image file <_io.BytesIO object at 0x7f0a6ecb1780> ``` and also further down ``` odoo.exceptions.UserError: ('This file could not be decoded as an image file. Please try with a different file.', '') ``` Examples of such files are CAD files (mimetype: image/vnd.dwg) For a list of all mimetypes starting with "image/" see: https://www.iana.org/assignments/media-types/media-types.xhtml#image
ddf945c
to
d8fde2e
Compare
Done. Thank you again for the support with this issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ocabot merge patch
Please fw-port it to upper versions.
This PR looks fantastic, let's merge it! |
Congratulations, your PR was merged at 3d537d8. Thanks a lot for contributing to OCA. ❤️ |
The method _compute_image_1920 of dms_file checks if the file is of mimetype image and tries to use it as a thumbnail. However, there are several types of image files that Odoo/PIL cannot work with, leading to the following error:
and also further down
Examples of such files are CAD files (mimetype: image/vnd.dwg) For a list of all mimetypes starting with "image/" see: https://www.iana.org/assignments/media-types/media-types.xhtml#image