简体   繁体   English

如何使用 Boto3 将空文件夹上传到 S3?

[英]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?如何使用 Boto 3 Python 将空文件夹上传到 S3?

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 : S3 并没有真正的文件夹

Amazon S3 has a flat structure instead of a hierarchy like you would see in a file system. Amazon S3 具有平面结构,而不是您在文件系统中看到的层次结构。 However, for the sake of organizational simplicity, the Amazon S3 console supports the folder concept as a means of grouping objects.但是,为了组织简单,Amazon S3 控制台支持将文件夹概念作为对对象进行分组的一种方式。 Amazon S3 does this by using a shared name prefix for objects (that is, objects that have names that begin with a common string). Amazon S3 通过为对象(即名称以通用字符串开头的对象)使用共享名称前缀来实现这一点。

Since folders are just part of object names, you can't have empty folders in S3.由于文件夹只是 object 名称的一部分,因此在 S3 中不能有空文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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