image - is there a way to store a file from url into s3's specific folder, not just into the root? -


found way upload file url s3 bucket there way direct specific folder or create folder?

i working store s3's root using code below

def save_image_s3(self, img_url, img_name):     """saves image in img_url s3 name img_name"""     conn = boto.connect_s3(settings.aws_access_key_id, settings.aws_secret_access_key)     bucket = conn.get_bucket(settings.aws_storage_bucket_name)     k = key(bucket)     k.key = img_name     fp = stringio.stringio(urllib2.urlopen(img_url).read())     k.set_contents_from_file(fp)     return img_name 

again, save bucket's root directory not sure how can direct save existing folder or make new folder if folder not exist

thanks in advance

you close, can set k.key full "path" in bucket object. example:

k.key = 'photos/%s' % img_name 

this save consider "folder" named photos. there no need folder created first, since s3 folders not exist implied appearance of 1 or more / appearing within object keys. not add / @ beginning.


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -