Reputation: 13
I'm trying to use boto in python to loop through and upload files to my aws bucket. I can successfully upload to my root bucket, but have been unable to upload to a specific prefix. Here is the snip I have:
conn = S3Connection(aws_access_key_id=key, aws_secret_access_key=secret)
bucket = conn.get_bucket('mybucket')
k = boto.s3.key.Key(bucket)
k.key = u
k.set_contents_from_filename(u)
It must be something simple, I have looked through other posts and have been unable to figure this out.
Thanks
Upvotes: 1
Views: 1700
Reputation: 6581
You need to build the full path of the key's name and then you can set its content:
#Connect to aws
conn = S3Connection(aws_access_key_id=key, aws_secret_access_key=secret)
bucket = conn.get_bucket('mybucket')
#Build path
path = 'prefix'
key_name = 'this_is_any.file'
full_key_name = os.path.join(path, key_name)
#Set and save in S3
k = bucket.new_key(full_key_name)
k.set_contents_from_filename(...)
Upvotes: 1