tuoheng_AIPlatform/AI_web_dsj/test/minio_upload.py

67 lines
1.5 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import io
import json
import cv2
import os
import urllib3
from minio import Minio
# MinIO
ENDPOINT = "minio-jndsj.t-aaron.com:2443" # MinIO服务器地址
ACCESS_KEY = "PJM0c2qlauoXv5TMEHm2" # 访问密钥
SECRET_KEY = "Wr69Dm3ZH39M3GCSeyB3eFLynLPuGCKYfphixZuI" # 密钥
# # 创建MinIO客户端
# minioClient = Minio(
# ENDPOINT,
# access_key=ACCESS_KEY,
# secret_key=SECRET_KEY,
# secure=True # 如果使用HTTPS设置为True
# )
# 创建MinIO客户端
minioClient = Minio(
ENDPOINT,
access_key=ACCESS_KEY,
secret_key=SECRET_KEY
)
aa = 'yolov5.pt' # 本地文件名
code = "027"
version = "V1.6"
# 构建 bucket 名称和对象路径
bucket_name = "algorithm" # 根据实际情况可能需要调整
weights = "weights"
object_path = f"{weights}/{code}/{version}/{aa}" # 在 MinIO 中的存储路径
try:
# 上传文件到 MinIO
result = minioClient.fput_object(
bucket_name=bucket_name,
object_name=object_path, # 目标路径
file_path=aa, # 本地文件路径
)
print("文件上传成功:")
print(f"Bucket: {result.bucket_name}")
print(f"Object: {result.object_name}")
print(f"ETag: {result.etag}")
# 检查 bucket 是否存在
if minioClient.bucket_exists("th-dsp"):
print("th-dsp exists")
else:
print("th-dsp does not exist")
except Exception as e:
print(f"上传失败: {e}")