Skip to content

Commit

Permalink
Fix base64 decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
laurynas committed May 5, 2024
1 parent bf25e70 commit a462d5e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ def reset_meter(meter_id):
def __request_image():
image_data = request.get_data()

# if 'base64' in image_data.decode('utf-8'):
# image_data = image_data.decode('utf-8').split('base64,')[1]
# image_data = base64.b64decode(image_data)
try:
image_data_str = image_data.decode('utf-8')

if 'base64' in image_data_str:
image_data_b64 = image_data_str.split('base64,')[1]
image_data = base64.b64decode(image_data_b64)
except UnicodeDecodeError:
pass

return Image.open(BytesIO(image_data))

0 comments on commit a462d5e

Please sign in to comment.