import requests def upload_to_oss(file_path): """ Uploads a file to OSS using the provided API endpoint. URL: https://crmapi.dcjxb.yunzhixue.cn/file/upload Method: POST Form-data: parameter 'file' """ url = "https://crmapi.dcjxb.yunzhixue.cn/file/upload" try: with open(file_path, 'rb') as f: files = {'file': f} response = requests.post(url, files=files) response.raise_for_status() result = response.json() # Assuming the response contains the URL in a specific field # We'll need to check the actual response format # Typical format: {"code": 200, "data": {"url": "..."}} or similar if result.get('code') == 200 or result.get('success'): # Extract URL - adjusting based on common API patterns data = result.get('data', {}) if isinstance(data, str): return data return data.get('url') or data.get('fileUrl') or result.get('url') else: print(f"Upload failed: {result}") return None except Exception as e: print(f"Error uploading to OSS: {e}") return None