“pangjh3” commited on
Commit
59ccfe2
·
1 Parent(s): 3d1e553

modified: src/oss/oss_file_manager.py

Browse files
Files changed (1) hide show
  1. src/oss/oss_file_manager.py +29 -0
src/oss/oss_file_manager.py CHANGED
@@ -201,6 +201,35 @@ class OSSFileManager:
201
  logger.error(f"下载文件内容失败: {oss_file_path}, 错误: {e}")
202
  return None
203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  def upload_file(self, local_file_path: str, oss_file_path: str) -> bool:
205
  """
206
  上传本地文件到OSS(别名方法)
 
201
  logger.error(f"下载文件内容失败: {oss_file_path}, 错误: {e}")
202
  return None
203
 
204
+ def upload_file_content(self, content: str, object_key: str) -> bool:
205
+ """
206
+ 直接上传字符串内容到OSS
207
+
208
+ Args:
209
+ content: 要上传的字符串内容
210
+ object_key: OSS对象键(文件路径)
211
+
212
+ Returns:
213
+ 上传是否成功
214
+ """
215
+ try:
216
+ # 将字符串转换为字节
217
+ if isinstance(content, str):
218
+ content_bytes = content.encode('utf-8')
219
+ else:
220
+ content_bytes = content
221
+
222
+ # 直接上传内容到OSS
223
+ self.bucket.put_object(object_key, content_bytes)
224
+
225
+ logger.info(f"上传内容成功: {object_key} ({len(content_bytes)} bytes)")
226
+ return True
227
+
228
+ except Exception as e:
229
+ logger.error(f"上传内容失败: {object_key}, 错误: {e}")
230
+ return False
231
+
232
+
233
  def upload_file(self, local_file_path: str, oss_file_path: str) -> bool:
234
  """
235
  上传本地文件到OSS(别名方法)