memestream bb

This commit is contained in:
Nathan Rashleigh committed 2024-04-08 00:34:30 +10:00
1 parent de58045c86
commit d82a7fdf1e
6 files changed
+147 -98

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
from minio import Minio
def upload(config, document, source_file):
assert config['MINIO_URL']
client = Minio(config['MINIO_URL'],
access_key=config['MINIO_ACCESS_KEY'],
secret_key=config['MINIO_SECRET_KEY'],
)
# The destination bucket and filename on the MinIO server
bucket_name = config['UPLOAD_BUCKET']
destination_file = document.url
# Make the bucket if it doesn't exist.
found = client.bucket_exists(bucket_name)
if not found:
client.make_bucket(bucket_name)
print("Created bucket", bucket_name)
else:
print("Bucket", bucket_name, "already exists")
# Upload the file, renaming it in the process
client.fput_object(
bucket_name, destination_file, source_file,
)
print(
source_file, "successfully uploaded as object",
destination_file, "to bucket", bucket_name,
)