2.Create and Manage Buckets

A bucket in MCS is a logical container for storing files and folders.

2.1 Create a new bucket

Use the create_bucket method to create a new bucket:

from swan_mcs import APIClient, BucketAPI
mcs_api = APIClient("<API_KEY>", "<ACCESS_TOKEN>", "<CHAIN_NAME>")
bucket_client = BucketAPI(mcs_api)

bucket_client.create_bucket("<BUCKET_NAME>")

2.2 List existing buckets

List all existing buckets using list_buckets:

from swan_mcs import APIClient, BucketAPI
mcs_api = APIClient("<API_KEY>", "<ACCESS_TOKEN>", "<CHAIN_NAME>")
bucket_client = BucketAPI(mcs_api)

for i in bucket_client.list_buckets():
    print(i.to_json())

2.3 Get bucket information

get_bucket(bucket_name)

from swan_mcs import APIClient, BucketAPI
mcs_api = APIClient("<API_KEY>", "<ACCESS_TOKEN>", "<CHAIN_NAME>")
bucket_client = BucketAPI(mcs_api)

print(bucket_client.get_bucket("<BUCKET_NAME>").to_json())

2.4 Create folder

create_folder(bucket_name, folder_name, prefix='')

The create_folder the method allows you to create a folder in the specified bucket. It accepts buckets name, folder names, and prefixes. The folder will be created in bucket_name/prefix/folder_name

from swan_mcs import APIClient, BucketAPI
mcs_api = APIClient("<API_KEY>", "<ACCESS_TOKEN>", "<CHAIN_NAME>")
bucket_client = BucketAPI(mcs_api)

# If you want to place the folder directly in the root directory, you can leave the prefix field empty
bucket_client.create_folder("<BUCKET_NAME>","<FOLDER_NAME>","<PREFIX>")

Parameters

  • bucket_name: The name of the bucket

  • folder_name: The name of the folder to create

  • prefix: The prefix for the folder's object name

Last updated