fix: add video format detection for uploaded files in image.py
parent
6af51a4235
commit
79fce87e93
|
|
@ -25,9 +25,19 @@ class VolcanicEngineImage(MaxKBBaseModel, BaseChatOpenAI):
|
||||||
def is_cache_model():
|
def is_cache_model():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def upload_file_and_get_url(self, file_stream, file_name):
|
def upload_file_and_get_url(self, file_stream, file_name):
|
||||||
"""上传文件并获取文件URL"""
|
"""上传文件并获取文件URL"""
|
||||||
base64_video = base64.b64encode(file_stream).decode("utf-8")
|
base64_video = base64.b64encode(file_stream).decode("utf-8")
|
||||||
video_format = mimetypes.guess_type(file_name)[0]
|
video_format = get_video_format(file_name)
|
||||||
return f'data:{video_format};base64,{base64_video}'
|
return f'data:{video_format};base64,{base64_video}'
|
||||||
|
|
||||||
|
|
||||||
|
def get_video_format(file_name):
|
||||||
|
extension = file_name.split('.')[-1].lower()
|
||||||
|
format_map = {
|
||||||
|
'mp4': 'video/mp4',
|
||||||
|
'avi': 'video/avi',
|
||||||
|
'mov': 'video/mov',
|
||||||
|
'wmv': 'video/x-ms-wmv'
|
||||||
|
}
|
||||||
|
return format_map.get(extension, 'video/mp4')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue