4.Retrieve and Download Files

4.1 List files in a bucket

Get a list of file information from one of your buckets

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

for i in bucket_client.list_files("<BUCKET_NAME>", '<PREFIX>', "<LIMIT>", '<OFFSET>'):
    print(i.to_json())

4.2 Get file information

Get the file information of a file in one of your buckets

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

print(bucket_client.get_file("<BUCKET_NAME>", "<OBJECT_NAME>").to_json())

Parameters

  • bucket_name: The name of the bucket

  • object_name: The object name of the file

4.3 Download a file

Downloads the file (located using bucket_name/object_name from IPFS and writes it to local_filename

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

bucket_client.download_file("<BUCKET_NAME>", "<OBJECT_NAME>", "<LOCAL_FILENAME>")

Parameters

  • bucket_name: The name of the bucket

  • object_name: The object name to download

  • local_filename: The download destination and filename

Last updated