Created
February 23, 2012 23:14
-
-
Save robbyt/1895635 to your computer and use it in GitHub Desktop.
boto etag hash auto verification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto | |
s3 = boto.connect_s3() | |
bucket = s3.get_bucket('robs-super-bucket') | |
d = bucket.new_key() | |
file1 = open('testfile.txt', 'r') | |
file2 = open('otherfile.txt', 'r') | |
# build the hash from file1 | |
d.etag = d.compute_md5(file) | |
# but upload file2... <kaboom!> | |
d.send_file(file2) | |
# If you set the etag header before uploading a file to s3 using boto, | |
# s3 will compute the md5 on their side and reject the upload if the | |
# sum on their side does not match the sum that you set prior to upload | |
# | |
# e.g., | |
# S3DataError: BotoClientError: ETag from S3 did not match computed MD5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this gist. Should line 11 be
d.etag = d.compute_md5(file1)
though?