Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
683e6ca3
Commit
683e6ca3
authored
May 02, 2024
by
Timothy J. Baek
Browse files
fix
parent
989a4d31
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
10 deletions
+22
-10
backend/apps/images/main.py
backend/apps/images/main.py
+22
-10
No files found.
backend/apps/images/main.py
View file @
683e6ca3
...
@@ -317,19 +317,31 @@ class GenerateImageForm(BaseModel):
...
@@ -317,19 +317,31 @@ class GenerateImageForm(BaseModel):
def
save_b64_image
(
b64_str
):
def
save_b64_image
(
b64_str
):
try
:
try
:
header
,
encoded
=
b64_str
.
split
(
","
,
1
)
image_id
=
str
(
uuid
.
uuid4
())
mime_type
=
header
.
split
(
";"
)[
0
]
img_data
=
base64
.
b64decode
(
encoded
)
if
","
in
b64_str
:
header
,
encoded
=
b64_str
.
split
(
","
,
1
)
mime_type
=
header
.
split
(
";"
)[
0
]
image_id
=
str
(
uuid
.
uuid4
())
img_data
=
base64
.
b64decode
(
encoded
)
image_format
=
mimetypes
.
guess_extension
(
mime_type
)
image_format
=
mimetypes
.
guess_extension
(
mime_type
)
image_filename
=
f
"
{
image_id
}{
image_format
}
"
file_path
=
IMAGE_CACHE_DIR
/
f
"
{
image_filename
}
"
with
open
(
file_path
,
"wb"
)
as
f
:
f
.
write
(
img_data
)
return
image_filename
else
:
image_filename
=
f
"
{
image_id
}
.png"
file_path
=
IMAGE_CACHE_DIR
.
joinpath
(
image_filename
)
img_data
=
base64
.
b64decode
(
b64_str
)
# Write the image data to a file
with
open
(
file_path
,
"wb"
)
as
f
:
f
.
write
(
img_data
)
return
image_filename
image_filename
=
f
"
{
image_id
}{
image_format
}
"
file_path
=
IMAGE_CACHE_DIR
/
f
"
{
image_filename
}
"
with
open
(
file_path
,
"wb"
)
as
f
:
f
.
write
(
img_data
)
return
image_filename
except
Exception
as
e
:
except
Exception
as
e
:
log
.
exception
(
f
"Error saving image:
{
e
}
"
)
log
.
exception
(
f
"Error saving image:
{
e
}
"
)
return
None
return
None
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment