3.Upload Files and Folders

3.1 Upload a single file

upload_file(bucket_name, object_name, file_path, replace=False)

Uploads a file to a bucket. Use the bucket_name to select the bucket, and object_name to select the path and file name of the uploaded file. file_path is the local path of the file.

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

# Object name is the destination path you want to upload to the bucket
# For example, if you want to upload the testfile.json file to path 111/222 in the TEST bucket, you would write: 
# bucket_client.upload_file("TEST", "111/222/testfile.json", "<FILE_PATH>")
bucket_client.upload_file("<BUCKET_NAME>", "<OBJECT_NAME>", "<FILE_PATH>")

Parameters

  • bucket_name: The name of the bucket

  • object_name: The object name of the file ex. 'folder1/file.png' will upload the file as file.png inside bucket_name/folder1

  • file_path: The local file path

  • replace: File's of the same name cannot be uploaded. When replace is set to True, it will overwrite the previous file of the same name.

Return

Returns a File Object

3.2 Upload a folder

Uploads folder_path as a MCS folder under bucket_name/object_name

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

bucket_client.upload_folder("<BUCKET_NAME>", "<OBJECT_NAME>", "<FOLDER_PATH>")

Parameters

  • bucket_name: The name of the bucket

  • object_name: The object name for the folder

  • folder_path: Local path of your folder

Return

Returns a list of File Objects

3.3 Upload as IPFS folder

Uploads folder_path as an IPFS folder to MCS. This gives the folder its own CID, sharable to others.

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

bucket_client.upload_ipfs_folder("<BUCKET_NAME>", "<OBJECT_NAME>", "<FOLDER_PATH>")

Parameters

  • bucket_name: The name of the bucket

  • object_name: The object name for the folder

  • folder_path: Local path of your folder

Return

Returns a File Object for your IPFS folder

Last updated