简体   繁体   中英

Boto3 : Download file from S3

Trying to download an older version of a file using boto3. I currently have this to download the latest version and this works.

get_obj = s3.download_file(
        Bucket="my_bucket",
        Key="testfile.txt",
        Filename='myfile'
        )

However I want to grab a previous version of the file and going thru the docs I see that download_object does allow extra args . More docs here

So I changed my code to this:

data = {'VersionId': prev_ver_id}

get_obj = s3.download_file(
        Bucket="my_bucket",
        Key="testfile.txt",
        Filename='myfile',
        **data)

However this keeps throwing TypeError: download_file() got an unexpected keyword argument 'VersionId'

Im not sure what Im missing here.

You have to pass the extra args in a dict:

response = s3.download_file(
    Bucket="my_bucket",
    Key="testfile.txt",
    Filename='myfile',
    ExtraArgs={'VersionId': prev_ver_id},
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM