Created
March 29, 2019 13:52
-
-
Save dkatz23238/d4f6ef66547024a253039c2cd8987a25 to your computer and use it in GitHub Desktop.
Write a file to minio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from minio import Minio | |
from minio.error import ResponseError, BucketAlreadyOwnedByYou, BucketAlreadyExists | |
import os | |
import glob | |
import uuid | |
MINIO_PORT = 9000 | |
HOST_URI = <Minio Host URI> | |
OUTPUT_BUCKET_NAME = <BUCKET NAME> | |
ACCESS_KEY = <ACCESS KEY> | |
SECRET_KEY = <SECRET KEY> | |
TEST_DOC_NAME = "test-doc-%s.txt" % str(uuid.uuid4()) | |
# Write a mock document | |
with open("./%s" % TEST_DOC_NAME, "w") as f: | |
f.write("hello!") | |
minioClient = Minio('%s:%s' % (HOST_URI, MINIO_PORT), | |
access_key= ACCESS_KEY, | |
secret_key= SECRET_KEY, | |
secure=False) | |
try: | |
minioClient.make_bucket(OUTPUT_BUCKET_NAME) | |
except BucketAlreadyOwnedByYou as err: | |
pass | |
except BucketAlreadyExists as err: | |
pass | |
except ResponseError as err: | |
raise | |
try: | |
object = minioClient.fput_object( | |
bucket_name=OUTPUT_BUCKET_NAME, object_name=TEST_DOC_NAME, file_path="./%s" % TEST_DOC_NAME | |
) | |
print("FPUT COMPLETE!") | |
print(object) | |
except ResponseError as err: | |
print(err) | |
print("Cleaning up...") | |
for f in glob.glob("./*.txt"): | |
os.remove(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python -m pip install minio