123456789101112131415161718192021222324252627282930313233343536 |
- from minio import Minio
- from minio.error import S3Error
- # Source code imported from https://docs.min.io/docs/python-client-quickstart-guide.html
- def main():
- # Create a client with the MinIO server playground, its access key
- # and secret key.
- client = Minio(
- "172.17.0.2:9000",
- access_key="minio",
- secret_key="miniokey",
- secure=False,
- )
- # Make bucket if not exist.
- found = client.bucket_exists("my-bucket")
- if not found:
- client.make_bucket("my-bucket")
- else:
- print("Bucket 'my-bucket' already exists")
- # Upload
- client.fput_object(
- "my-bucket", "hello.txt", "./test/data/hello.txt",
- )
- print("Success")
- if __name__ == "__main__":
- try:
- main()
- except S3Error as exc:
- print("error occurred.", exc)
|