简体   繁体   中英

How to upload an empty folder to S3 using Boto3?

My program backs up all the files in the directory, except for empty folders. How do you upload an empty folder into S3 using Boto 3, Python?

for dirName, subdirList, fileList in os.walk(path):
    # for each directory, walk through all files
    for fname in fileList:

        current_key = dirName[dir_str_index:] +"\\"+ fname
        current_key = current_key.replace("\\", "/")

S3 doesn't really have folders :

Amazon S3 has a flat structure instead of a hierarchy like you would see in a file system. However, for the sake of organizational simplicity, the Amazon S3 console supports the folder concept as a means of grouping objects. Amazon S3 does this by using a shared name prefix for objects (that is, objects that have names that begin with a common string).

Since folders are just part of object names, you can't have empty folders in S3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM