Skip to content

Commit

Permalink
🚑 when the "image_resize_image" function was called, they received th…
Browse files Browse the repository at this point in the history
…e error "binascii.Error: decoding with base64 codec failed (Error: Incorrect padding)", since the value of the binary field is the URL, not the base_64 string
  • Loading branch information
Rafis Bikbov committed Nov 14, 2018
1 parent 6c8f6f9 commit 493c5ef
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ir_attachment_url/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"summary": """Use attachment URL and upload data to external storage""",
"category": "Tools",
"images": [],
"version": "11.0.1.1.5",
"version": "11.0.1.1.6",
"application": False,

"author": "IT-Projects LLC, Ildar Nasyrov",
Expand Down
5 changes: 5 additions & 0 deletions ir_attachment_url/doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
`1.1.6`
-------

- **Fix** When the "image_resize_image" function was called, they received the error "binascii.Error: decoding with base64 codec failed (Error: Incorrect padding)", since the value of the binary field is the URL, not the base_64 string.

`1.1.5`
-------

Expand Down
54 changes: 54 additions & 0 deletions ir_attachment_url/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,58 @@ def is_url(value):
return isinstance(value, str) and re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', value)


super_image_resize_image = tools.image_resize_image


def updated_image_resize_image(base64_source, size=(1024, 1024), encoding='base64', filetype=None, avoid_if_small=False):
source_for_check = base64_source.decode("utf-8") if isinstance(base64_source, bytes) else base64_source
if is_url(source_for_check):
return source_for_check
return super_image_resize_image(base64_source, size=size, encoding=encoding, filetype=filetype, avoid_if_small=avoid_if_small)


def updated_image_resize_image_big(base64_source, size=(1024, 1024), encoding='base64', filetype=None, avoid_if_small=True):
""" copy-pasted from odoo/tools/image.py::image_resize_image_big
because we rewrite image_resize_image function.
"""
return updated_image_resize_image(base64_source, size, encoding, filetype, avoid_if_small)


def updated_image_resize_image_medium(base64_source, size=(128, 128), encoding='base64', filetype=None, avoid_if_small=False):
""" copy-pasted from odoo/tools/image.py::image_resize_image_medium
because we rewrite image_resize_image function.
"""
return updated_image_resize_image(base64_source, size, encoding, filetype, avoid_if_small)


def updated_image_resize_image_small(base64_source, size=(64, 64), encoding='base64', filetype=None, avoid_if_small=False):
""" copy-pasted from odoo/tools/image.py::image_resize_image_small
because we rewrite image_resize_image function.
"""
return updated_image_resize_image(base64_source, size, encoding, filetype, avoid_if_small)


def updated_image_get_resized_images(base64_source, return_big=False, return_medium=True, return_small=True,
big_name='image', medium_name='image_medium', small_name='image_small',
avoid_resize_big=True, avoid_resize_medium=False, avoid_resize_small=False):
""" copy-pasted from odoo/tools/image.py::image_get_resized_images
because we rewrite image_resize_image function.
"""
return_dict = dict()
if isinstance(base64_source, tools.pycompat.text_type):
base64_source = base64_source.encode('ascii')
if return_big:
return_dict[big_name] = updated_image_resize_image_big(base64_source, avoid_if_small=avoid_resize_big)
if return_medium:
return_dict[medium_name] = updated_image_resize_image_medium(base64_source, avoid_if_small=avoid_resize_medium)
if return_small:
return_dict[small_name] = updated_image_resize_image_small(base64_source, avoid_if_small=avoid_resize_small)
return return_dict


tools.image_resize_images = updated_image_resize_images
tools.image_resize_image = updated_image_resize_image
tools.image_resize_image_big = updated_image_resize_image_big
tools.image_resize_image_medium = updated_image_resize_image_medium
tools.image_resize_image_small = updated_image_resize_image_small
tools.image_get_resized_images = updated_image_get_resized_images

0 comments on commit 493c5ef

Please sign in to comment.