未验证 提交 8b903322 编写于 作者: A AUTOMATIC1111 提交者: GitHub

Merge pull request #7140 from vladmandic/api-decode-image

Add exception handling to API image decode
......@@ -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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册