49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
|
|
import os
|
|
from minio import Minio
|
|
from minio.error import S3Error
|
|
|
|
bucket="300bdf2b-a150-406e-be63-d28bd29b409f"
|
|
# 替换为你的MinIO服务器地址、访问密钥和秘密密钥
|
|
def getClient():
|
|
minio_client = Minio(
|
|
"222.212.85.86:9000",
|
|
access_key="WuRenJi",
|
|
secure=False,
|
|
secret_key="WRJ@2024",)
|
|
return minio_client
|
|
|
|
def getPath2(object):
|
|
#dir="C:/sy/movies/"
|
|
dir=os.getcwd()+"/"
|
|
baseName=object
|
|
s1=baseName.rfind("/")
|
|
dir2=(dir+baseName[0:s1+1]).replace("/","\\")
|
|
fName=baseName[s1+1:int(len(baseName))]
|
|
os.makedirs(dir2, exist_ok=True)
|
|
file_path = os.path.join(dir2, fName)
|
|
return file_path
|
|
|
|
def upLoad(obj,path):
|
|
try:
|
|
minio_client=getClient()
|
|
minio_client.fput_object(bucket, obj, path)
|
|
return True
|
|
except S3Error as e:
|
|
return False
|
|
|
|
def downLoad(obj):
|
|
path=getPath2(obj)
|
|
if os.path.exists(path):
|
|
return path
|
|
# 从MinIO的存储桶和对象名称下载
|
|
try:
|
|
minio_client=getClient()
|
|
minio_client.fget_object(bucket, obj, path)
|
|
return path
|
|
except S3Error as e:
|
|
return ""
|
|
|
|
if __name__ == '__main__':
|
|
upLoad("aaa/yolo_api.py","yolo_api.py")
|