import io
import json

import cv2
import urllib3
from minio import Minio

# MinIO

minioClient = Minio('192.168.12.5:9000',
                    access_key='RoZc1NbZ6oAC4lTV',
                    secret_key='wC01Lup6SIoahwfSrYcoF2gSF3mPy6gJ',
                    secure=False)
aa = r'C:\Users\chenyukun\Desktop\shipin\DJI_20211229100908_0001_S.mp4'
# # 创建存储桶
# img = cv2.imread(r"D:\work\alg\tuoheng_alg\test\image\1.jpg")
# ai_result, ai_image = cv2.imencode(".jpg", img)
# # minioClient.make_bucket("test/bb")
# print(len(ai_image))
# minioClient.put_object('test', '1.jpg', io.BytesIO(ai_image.tobytes()), len(ai_image))
result = minioClient.fput_object("test", "aa3.mp4", aa)
print(result.__dict__)
# 查看桶信息
# buckets = minioClient.list_buckets()
# for bucket in buckets:
#     print(bucket.name, bucket.creation_date)
# 判断桶是否存在
if minioClient.bucket_exists("my-bucket"):
    print("my-bucket exists")
else:
    print("my-bucket does not exist")