CustomIWMServer/customiwmserver/object_storage.py

30 lines
731 B
Python
Raw Permalink Normal View History

2022-12-17 18:10:58 +00:00
from minio import Minio
from os import getenv
import json
import io
print("---")
print(getenv("S3_ENDPOINT"),
getenv("S3_ACCESS_KEY"),
getenv("S3_SECRET_KEY"),
json.loads(getenv("S3_IS_SECURE", "false")), sep="\n"
)
print("---")
client = Minio(
getenv("S3_ENDPOINT"),
access_key=getenv("S3_ACCESS_KEY"),
secret_key=getenv("S3_SECRET_KEY"),
secure=json.loads(getenv("S3_IS_SECURE", "false")),
)
ThumbsBucket = "iwm-user-thumbnails"
if not client.bucket_exists(ThumbsBucket):
client.make_bucket(ThumbsBucket)
async def upload_thumbnail(data, levelID):
# file = io.BytesIO(await data.read())
client.put_object(ThumbsBucket, f"{levelID}.png", data.file, length=-1, part_size=10*1024*1024)