diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-01-24 06:54:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-24 06:54:20 +0000 |
commit | 8b903322e66a694245970832f7fa89e2faa2ad0a (patch) | |
tree | 8e18681f60a14f7a5251cf124b881738be7826a4 | |
parent | 848ef919b37bd43a576628d300bd27f203f71ac5 (diff) | |
parent | 45e270dfc853216b2c413f915946f0f2842e57a4 (diff) | |
download | stable-diffusion-webui-gfx803-8b903322e66a694245970832f7fa89e2faa2ad0a.tar.gz stable-diffusion-webui-gfx803-8b903322e66a694245970832f7fa89e2faa2ad0a.tar.bz2 stable-diffusion-webui-gfx803-8b903322e66a694245970832f7fa89e2faa2ad0a.zip |
Merge pull request #7140 from vladmandic/api-decode-image
Add exception handling to API image decode
-rw-r--r-- | modules/api/api.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/modules/api/api.py b/modules/api/api.py index b1dd14cc..e6e31e41 100644 --- a/modules/api/api.py +++ b/modules/api/api.py @@ -53,7 +53,11 @@ def setUpscalers(req: dict): def decode_base64_to_image(encoding): if encoding.startswith("data:image/"): encoding = encoding.split(";")[1].split(",")[1] - return Image.open(BytesIO(base64.b64decode(encoding))) + try: + image = Image.open(BytesIO(base64.b64decode(encoding))) + return image + except Exception as err: + raise HTTPException(status_code=500, detail="Invalid encoded image") def encode_pil_to_base64(image): with io.BytesIO() as output_bytes: |