Cloudian is fully compatible with S3, so it's convenient to use the AWS SDK! Last time tried to transfer files with Python (boto3).
This time, I would like to list the objects stored in the bucket of object storage with Python (boto3).
Use list_objects () to check the existence of files (objects) uploaded to Cloudian. list_objects () returns a lot of information in Python's dict type. In the following example, only the key and size of the object and the date and time of the last modification are displayed from the returned values.
test.py
import boto3
client = boto3.client(
's3',
endpoint_url='https://xxx.yyy.com'
)
#Bucket name:List all pythonbucket1 objects
for obj in client.list_objects(Bucket='pythonbucket1')['Contents']:
print(obj['Key'], obj['Size'],
obj['LastModified'].strftime("%Y/%m/%d %H:%M:%S"))
10mb.dat 10485760 2020/12/14 03:12:38
I tried to display a list of objects with Python (boto3).
Next time, I would like to operate object storage/Cloudian in various ways with Python.
Recommended Posts