Permalink
Browse files

🚑 when the "image_resize_image" function was called, they received th…

…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...
RafiZz committed Nov 2, 2018
1 parent c61d11b commit 8f1199bcceb78d9abacb03a31616663ea4df3036
Showing with 65 additions and 1 deletion.
  1. +1 −1 ir_attachment_url/__manifest__.py
  2. +5 −0 ir_attachment_url/doc/changelog.rst
  3. +59 −0 ir_attachment_url/models/image.py
@@ -3,7 +3,7 @@
"summary": """Use attachment URL and upload data to external storage""",
"category": "Tools",
"images": [],
"version": "12.0.1.1.5",
"version": "12.0.1.1.6",
"application": False,

"author": "IT-Projects LLC, Ildar Nasyrov",
@@ -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`
-------

@@ -31,4 +31,63 @@ 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, upper_limit=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, upper_limit=upper_limit)


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, sizes=None):
""" copy-pasted from odoo/tools/image.py::image_get_resized_images
because we rewrite image_resize_image function.
"""
if not sizes:
sizes = {}
return_dict = dict()
size_big = sizes.get(big_name, (1024, 1024))
size_medium = sizes.get(medium_name, (128, 128))
size_small = sizes.get(small_name, (64, 64))
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, size=size_big)
if return_medium:
return_dict[medium_name] = updated_image_resize_image_medium(base64_source, avoid_if_small=avoid_resize_medium, size=size_medium)
if return_small:
return_dict[small_name] = updated_image_resize_image_small(base64_source, avoid_if_small=avoid_resize_small, size=size_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 8f1199b

Please sign in to comment.