2024-12-11 11:35:41 +08:00
|
|
|
import io
|
2024-09-26 06:09:05 +00:00
|
|
|
import json
|
|
|
|
|
import logging
|
2024-12-11 11:16:41 +08:00
|
|
|
import os
|
2024-09-26 06:09:05 +00:00
|
|
|
|
|
|
|
|
logger = logging.getLogger()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def oss_upload_json(oss_client, json_data, object_name):
|
|
|
|
|
try:
|
2024-12-11 11:16:41 +08:00
|
|
|
save_dir = os.path.join(os.getcwd(), "service/design_batch", "response_data")
|
|
|
|
|
if not os.path.exists(save_dir):
|
|
|
|
|
os.makedirs(save_dir)
|
|
|
|
|
# 处理文件
|
|
|
|
|
file_path = os.path.join(save_dir, object_name)
|
|
|
|
|
with open(file_path, 'w') as file:
|
2024-09-26 06:09:05 +00:00
|
|
|
json.dump(json_data, file, indent=4)
|
2024-12-11 11:35:41 +08:00
|
|
|
json_bytes = json.dumps(json_data).encode('utf-8')
|
|
|
|
|
oss_client.put_object("test", object_name, io.BytesIO(json_bytes), length=len(json_bytes), content_type="application/json")
|
2024-09-26 06:09:05 +00:00
|
|
|
except Exception as e:
|
|
|
|
|
logger.warning(str(e))
|