This commit is contained in:
2025-08-21 08:56:06 +08:00
parent f45ae8e942
commit c577687727
5 changed files with 24 additions and 8 deletions

View File

@@ -2,8 +2,10 @@ import base64
import json
import os
from Config.Config import OBS_SERVER, OBS_PREFIX
from JiMeng.Kit.JmCommon import JmCommon
from JiMeng.Kit.JmErrorCode import JmErrorCode
from Util.ObsUtil import ObsUploader
class JmTxt2Img:
@@ -47,6 +49,20 @@ class JmTxt2Img:
with open(save_img_path, 'wb') as f:
f.write(bytes_data)
print(f"文件保存成功!文件位置: {save_img_path}")
# 创建上传器实例
uploader = ObsUploader()
# 上传参数
object_key = OBS_PREFIX + "/" + file_path
# 执行上传
success, result = uploader.upload_file(object_key, file_path)
# 处理结果
if success:
logger.info(f'{file_path}上传成功!')
# 获取上传文件的 URL
file_url = f"https://{OBS_BUCKET}.{OBS_SERVER}/{object_key}"
img_url_list.append(file_url)
except Exception as e:
print(f"保存图片失败: {str(e)}")
raise Exception(f"保存图片失败: {str(e)}")