12-s3sendfile.py 514 B

12345678910111213141516171819202122
  1. #!/usr/bin/python
  2. """
  3. - Author : Nag m
  4. - Hack : Upload a file to s3 bucket using the method send_file
  5. - Info : Upload a file named
  6. - myfile.txt
  7. set_contents_from_filename vs send_file. set_contents_from_filename uses send_file
  8. Getting a HTTP 400 error
  9. """
  10. import boto
  11. def uploadfile():
  12. bucket = conn.get_bucket("101-s3-aws")
  13. obj = bucket.new_key("myfile2.txt")
  14. fp = open("myfile.txt", "r")
  15. obj.send_file(fp)
  16. if __name__ == "__main__":
  17. conn = boto.connect_s3()
  18. uploadfile()