import io
import json
import logging
import os

logger = logging.getLogger()


def oss_upload_json(oss_client, json_data, object_name):
    try:
        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:
            json.dump(json_data, file, indent=4)
        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")
    except Exception as e:
        logger.warning(str(e))
