import os
from minio import Minio
!pip install minio
client = Minio(
"qbittorrent:3000",
"minioadmin",
"minioadmin",
secure=False,
)
filename = "thalia_caetano15_279970453_1051143635478514_141905778914952102_n.mp4"
client.fput_object("test", filename, filename)
for obj in client.list_objects("test", recursive=True):
print(obj.object_name)
a = client.stat_object("test", "shoudl_break")
a = client.stat_object("test", filename)
dir(a)
type(a)
a.metadata
a.metadata.get('ETag')
a.size
os.stat(filename)
os.stat(filename).st_size
os.popen(f"md5sum {filename}").read()
!md5sum thalia_caetano15_279970453_1051143635478514_141905778914952102_n.mp4
# https://stackoverflow.com/questions/3431825/generating-an-md5-checksum-of-a-file
import hashlib
def hash_bytestr_iter(bytesiter, hasher, ashexstr=False):
for block in bytesiter:
hasher.update(block)
return hasher.hexdigest() if ashexstr else hasher.digest()
def file_as_blockiter(afile, blocksize=65536):
with afile:
block = afile.read(blocksize)
while len(block) > 0:
yield block
block = afile.read(blocksize)
def getmd5sum(filepath):
return hash_bytestr_iter(file_as_blockiter(open(filepath, 'rb')), hashlib.md5(), True)
getmd5sum(filename)
def check_diff_size(bucket, key, filepath):
try:
obj = client.stat_object(bucket, key)
obj_size = obj.size
fileobj = os.stat(filepath)
fileobj_size = fileobj.st_size
return obj_size == fileobj_size
except:
return False
check_diff_size("test", filename, filename)
import io
import json
data = {
"a": 2,
"b": 3
}
buf = io.BytesIO("asdfasdf".encode('utf-8'))
size = buf.getbuffer().nbytes
client.put_object("test", "testfile", buf, size)
client.get_object("test", "testfile").read().decode('utf-8')
def minio_save_key(bucket, key, content):
buf = io.BytesIO(content.encode('utf-8'))
size = buf.getbuffer().nbytes()
client.put_object(bucket, key, buf, size)
def minio_get_key(bucket, key):
return client.get_object(bucket, key).read().decode('utf-8')