且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 boto 获取 S3 对象的上次修改日期时间

更新时间:2022-11-07 11:49:27

以下是 Python/boto 代码片段,用于打印存储桶中所有键的 last_modified 属性:

>>>进口博托>>>s3 = boto.connect_s3()>>>桶 = s3.lookup('mybucket')>>>对于桶中的密钥:打印 key.name、key.size、key.last_modifiedindex.html 13738 2012-03-13T03:54:07.000Zmarkdown.css 5991 2012-03-06T18:32:43.000Z>>>

I'm writing a Python script that uploads files to S3 using boto librairy. I only want to upload changed files (which I can check by their "last modified" datetimes), but I can't find the Boto API endpoint to get the last modified date.

Here's a snippet of Python/boto code that will print the last_modified attribute of all keys in a bucket:

>>> import boto
>>> s3 = boto.connect_s3()
>>> bucket = s3.lookup('mybucket')
>>> for key in bucket:
       print key.name, key.size, key.last_modified
index.html 13738 2012-03-13T03:54:07.000Z
markdown.css 5991 2012-03-06T18:32:43.000Z
>>>