瀏覽代碼

Add extension to image filename

Rodrigo Agundez 3 月之前
父節點
當前提交
312f273a1b
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      backend/open_webui/routers/images.py

+ 4 - 2
backend/open_webui/routers/images.py

@@ -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)