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 6c8f6f9 commit 0f0185c7ae291acbc722f5b4c10d959935675b71
Showing with 41 additions and 1 deletion.
  1. +1 −1 ir_attachment_url/__manifest__.py
  2. +5 −0 ir_attachment_url/doc/changelog.rst
  3. +35 −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": "11.0.1.1.5",
"version": "11.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`
-------

@@ -28,4 +28,39 @@ 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)


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

0 comments on commit 0f0185c

Please sign in to comment.