You've already forked FrameTour-RenderWorker
							
							
		
			
				
	
	
		
			39 lines
		
	
	
		
			992 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			992 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import os
 | |
| 
 | |
| import requests
 | |
| 
 | |
| 
 | |
| def upload_to_oss(url, file_path):
 | |
|     """
 | |
|     使用签名URL上传文件到OSS
 | |
|     :param str url: 签名URL
 | |
|     :param str file_path: 文件路径
 | |
|     :return bool: 是否成功
 | |
|     """
 | |
|     with open(file_path, 'rb') as f:
 | |
|         try:
 | |
|             response = requests.put(url, data=f)
 | |
|             return response.status_code == 200
 | |
|         except Exception as e:
 | |
|             print(e)
 | |
|             return False
 | |
| 
 | |
| def download_from_oss(url, file_path):
 | |
|     """
 | |
|     使用签名URL下载文件到OSS
 | |
|     :param str url: 签名URL
 | |
|     :param Union[LiteralString, str, bytes] file_path: 文件路径
 | |
|     :return bool: 是否成功
 | |
|     """
 | |
|     file_dir, file_name = os.path.split(file_path)
 | |
|     if not os.path.exists(file_dir):
 | |
|         os.makedirs(file_dir)
 | |
|     try:
 | |
|         response = requests.get(url)
 | |
|         with open(file_path, 'wb') as f:
 | |
|             f.write(response.content)
 | |
|         return True
 | |
|     except Exception as e:
 | |
|         print(e)
 | |
|         return False
 |