stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Bug]: API img2img not accepting bare base64 strings

Open MaikoTan opened this issue 3 years ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What happened?

In the prototype version of API, the img2img accepts both data URLs and bare base64 strings. But recently I found that it only accept data URLs now, since the PR #3511 . If you still request the API with bare base64 strings, it would report an error like

  File "/***/stable-diffusion-webui/modules/api/api.py", line 84, in img2imgapi
    mask = decode_base64_to_image(mask)
  File "/***/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/processing_utils.py", line 45, in decode_base64_to_image
    content = encoding.split(";")[1]
IndexError: list index out of range

Steps to reproduce the problem

  1. Run webui with --api
  2. Request the api /sdapi/v1/img2img with base64 encoded image
  3. Error occurred.

What should have happened?

I think it should accept both type of it, just like the prototype did.

Commit where the problem happens

07d1bd426722b4c53b38ff682c5aab53177d8530

What platforms do you use to access UI ?

Windows, Linux

What browsers do you use to access the UI ?

Google Chrome

Command Line Arguments

--api

Additional information, context and logs

cc @bamarillo

MaikoTan avatar Nov 09 '22 01:11 MaikoTan

The standard way is dataURLs, this is inline with the new gradio return format which also used to be base64 only but now dataURLs.

aliencaocao avatar Nov 09 '22 02:11 aliencaocao

Sure, I can fix my code to use data URLs in requesting the API. But I think it still is better to catch the exception?

MaikoTan avatar Nov 09 '22 02:11 MaikoTan

fixed in https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/4977

ClashSAN avatar Dec 12 '22 06:12 ClashSAN