2

I'm trying to download file that has many versions from version-enabled bucket. Using the bellow code, it always download the file that has latest version.

s3 = boto3.resource('s3')
bucket = s3.Bucket("mybucket")
bucket.download_file("somefile", "/donwload/path/somefile.txt")

How can I specify which version I want to download for the "somefile" file?

1
  • Try specifying the VersionId in ExtraArgs Commented Dec 2, 2021 at 9:42

1 Answer 1

4

As per the comments, Bucket.download_file has an ExtraArgs parameter, where you can specify additional parameters that are passed down to the Client.get_object function that download_file wraps. From the documentation of get_object, you can see that the relevant argument is VersionId.

s3 = boto3.resource('s3')
bucket = s3.Bucket("mybucket")
bucket.download_file(
    "somefile",
    "/donwload/path/somefile.txt",
    ExtraArgs={"VersionId": "my_version"}
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.