简体   繁体   English

无法从S3存储桶下载文件?

[英]Not able to download files from S3 bucket?

This is the code i am using to download all the files from my S3 bucket is: 这是我用来从S3存储桶下载所有文件的代码是:

#Download all files from a bucket to a local folder
        LOCAL_PATH = "C\\s3\\"
        bucket_name = 'unrendered'
        # connect to the bucket
        bucket = conn.get_bucket(bucket_name)
        # go through the list of files
        for key in bucket.list():
            try:
                res = key.get_contents_to_filename(key.name).replace("\\", "//")
            except:
                print(key.name+":"+"FAILED")

The files in my S3 buckets are: 我的S3存储桶中的文件是:

在此处输入图片说明

The code only downloads the first file, but i cannot download the rest of the files which have names with directory address included. 该代码仅下载第一个文件,但我无法下载名称包含目录地址的其余文件。

Also, when i upload the files on S3 using boto, it does not create directories it creates files with names of directories included. 另外,当我使用boto在S3上上传文件时,它不会创建目录,而是创建包含目录名称的文件。 I know that s3 is flat data structure, but how can i create folder from the web interface. 我知道s3是平面数据结构,但是如何从Web界面创建文件夹。

In line #9, try replacing your line with this: 在第9行中,尝试用以下代码替换行:

   res = key.get_contents_to_filename(key.name.replace("\\", ""))

Does that work? 那样有用吗?

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

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