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 7d2d986 commit 9797269a426b82017ece1566f1d9cfdbdac3e9a6
Showing with 38 additions and 0 deletions.
  1. +38 −0 ir_attachment_url/models/image.py
@@ -31,4 +31,42 @@ 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)
def image_resize_image_decorator(original_image_resize_image):
def wrapper(base64_source, size=(1024, 1024), encoding='base64', filetype=None, avoid_if_small=False, upper_limit=False):
print('asdasdasd')
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 original_image_resize_image(base64_source, size=size, encoding=encoding, filetype=filetype, avoid_if_small=avoid_if_small, upper_limit=upper_limit)
return wrapper
image_resize_image = image_resize_image_decorator(tools.image_resize_image)
def 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 image_resize_image(base64_source, size, encoding, filetype, avoid_if_small)
def 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 image_resize_image(base64_source, size, encoding, filetype, avoid_if_small)
def 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 image_resize_image(base64_source, size, encoding, filetype, avoid_if_small)
tools.image_resize_images = updated_image_resize_images
tools.image_resize_image = image_resize_image
tools.image_resize_image_big = image_resize_image_big
tools.image_resize_image_medium = image_resize_image_medium
tools.image_resize_image_small = image_resize_image_small

0 comments on commit 9797269

Please sign in to comment.