31 lines
714 B
Python
31 lines
714 B
Python
"""Definition of put function."""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from io import BytesIO
|
|
|
|
from minio import Minio
|
|
|
|
|
|
def put(
|
|
client: Minio,
|
|
buffer: BytesIO,
|
|
object_name: str,
|
|
) -> None:
|
|
"""Put buffer in bucket in MinIO."""
|
|
assert isinstance(client, Minio)
|
|
assert isinstance(buffer, BytesIO)
|
|
assert isinstance(object_name, str)
|
|
bucket_name = os.getenv('MINIO_BUCKET_NAME', default=None)
|
|
assert isinstance(bucket_name, str)
|
|
# prepare for saving
|
|
num_bytes = buffer.tell()
|
|
buffer.seek(0)
|
|
# send data to bucket
|
|
client.put_object(
|
|
bucket_name=bucket_name,
|
|
object_name=object_name,
|
|
length=num_bytes,
|
|
data=buffer,
|
|
)
|