s3afe_3.py 725 B

12345678910111213141516171819
  1. def _upload(awskey, awssecret, filename, bucketname, keyname, acl):
  2. """
  3. Uploads a file to S3
  4. """
  5. try:
  6. conn = S3Connection(awskey, awssecret)
  7. bucket = conn.get_bucket(bucketname)
  8. key = bucket.new_key(keyname)
  9. #key.set_metadata("ETag", _hasher(filename))
  10. key.set_metadata("Cache-Control", "max-age=31104000")
  11. key.set_contents_from_filename(filename)
  12. key.set_acl(acl)
  13. except S3ResponseError as exc:
  14. if exc.status == 403:
  15. sys.exit('Error: Please check your Amazon credentials!')
  16. elif exc.status == 404:
  17. sys.exit('Error: Your bucket does not exist (yet)')
  18. else:
  19. print (filename, ' Upload successful!')