Skip to content

Commit 9b33361

Browse files
committed
Added simple s3 upload script
1 parent c5a98ed commit 9b33361

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

s3-upload.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/python
2+
3+
"""
4+
Upload a file to S3
5+
"""
6+
7+
from sys import argv, stdout
8+
from time import time
9+
10+
from boto.s3.key import Key
11+
from boto.s3.connection import S3Connection
12+
13+
def callback( transmitted, size ):
14+
"Progress callback for set_contents_from_filename"
15+
print '\r%d bytes transmitted of %d (%.2f%%)' % (
16+
transmitted, size, 100.0 * transmitted / size ),
17+
stdout.flush()
18+
19+
def uploadFile( bucket, filename ):
20+
"Upload a file to a bucket"
21+
print '* Uploading', filename, 'to bucket', bucket
22+
start = time()
23+
conn = S3Connection()
24+
bucket = conn.get_bucket( bucket )
25+
k = Key( bucket )
26+
k.key = filename
27+
k.set_contents_from_filename( filename, cb=callback, num_cb=100 )
28+
print
29+
elapsed = time() - start
30+
print "* elapsed time: %.2f seconds" % elapsed
31+
32+
if __name__ == '__main__':
33+
if len( argv ) != 3:
34+
print 'Usage: %s <bucket> <filename>'
35+
exit( 1 )
36+
bucket, filename = argv[ 1 : 3 ]
37+
uploadFile( bucket, filename )

0 commit comments

Comments
 (0)