You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import oss2
from WxMini.Milvus.Config.MulvusConfig import *
# 初始化 OSS Bucket
auth = oss2.Auth(ACCESS_KEY_ID, ACCESS_KEY_SECRET)
bucket = oss2.Bucket(auth, ENDPOINT, BUCKET_NAME)
def upload_mp3_to_oss(file_path, oss_object_name):
"""
上传本地 MP3 文件到 OSS
:param file_path: 本地 MP3 文件路径
:param oss_object_name: OSS 中存储的文件名
"""
try:
# 上传文件
with open(file_path, 'rb') as file:
bucket.put_object(oss_object_name, file)
print(f"文件 {file_path} 已成功上传到 OSS存储为 {oss_object_name}")
except Exception as e:
print(f"上传失败: {e}")
def upload_mp3_to_oss_from_memory(oss_object_name, audio_data):
"""
从内存上传 MP3 数据到 OSS
:param oss_object_name: OSS 中存储的文件名
:param audio_data: 音频数据bytes 类型)
"""
try:
# 上传音频数据
bucket.put_object(oss_object_name, audio_data)
print(f"音频数据已成功上传到 OSS存储为 {oss_object_name}")
except Exception as e:
print(f"上传失败: {e}")