mirror of
https://github.com/open-webui/open-webui
synced 2025-02-22 21:32:32 +00:00
Add extension to image filename
This commit is contained in:
parent
4974c9cbb0
commit
312f273a1b
@ -3,6 +3,7 @@ import base64
|
||||
import io
|
||||
import json
|
||||
import logging
|
||||
import mimetypes
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
@ -411,15 +412,16 @@ def load_url_image_data(url, headers=None):
|
||||
|
||||
|
||||
def upload_image(request, data, image_data, content_type, user):
|
||||
image_format = mimetypes.guess_extension(content_type)
|
||||
file = UploadFile(
|
||||
file=io.BytesIO(image_data),
|
||||
filename="image", # will be converted to a unique ID on upload_file
|
||||
filename=f"generated{image_format}", # will be converted to a unique ID on upload_file
|
||||
headers={
|
||||
"content-type": content_type,
|
||||
},
|
||||
)
|
||||
file_item = upload_file(request, file, user)
|
||||
file_body_path = IMAGE_CACHE_DIR.joinpath(f"{file_item.id}.json")
|
||||
file_body_path = IMAGE_CACHE_DIR.joinpath(f"{file_item.filename}.json")
|
||||
|
||||
with open(file_body_path, "w") as f:
|
||||
json.dump(data, f)
|
||||
|
Loading…
Reference in New Issue
Block a user