【问题标题】:getting PermissionError: [Errno 13] Permission denied while uploading to s3获取 PermissionError: [Errno 13] 上传到 s3 时权限被拒绝
【发布时间】:2022-01-24 20:58:19
【问题描述】:

当我尝试使用 python 和 boto3 将文件上传到我的 ASW s3 时,它工作正常,我能够成功地将它上传到 aws s3,但是当我尝试上传一个文件夹时,我得到了

getting PermissionError: [Errno 13]

我的代码是

def upload_to_aws(local_file, bucket, s3_file):
    s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,
                      aws_secret_access_key=SECRET_KEY)

    try:
        s3.upload_file(local_file, bucket, s3_file)
        print("Upload Successful")
        return True
    except FileNotFoundError:
        print("The file was not found")
        return False
    except NoCredentialsError:
        print("Credentials not available")
        return False 

【问题讨论】:

  • 进展如何?仍然不清楚你能做什么?

标签: python amazon-web-services amazon-s3 boto3


【解决方案1】:

upload_file 仅用于上传文件,不适用于文件夹。您必须遍历文件夹中的所有文件,并为每个文件执行upload_file 操作。

【讨论】:

    【解决方案2】:

    @Marcin 是对的。

    了解 s3 存储桶的结构也很重要。因为s3是一个对象存储,它实际上是没有文件夹结构的。 您在存储桶中创建的文件夹只是按文件名(如/**folder**/myfile.pdf)在视觉上分组的对象。 这样做是为了让我们可以更轻松地与对象交互。 但 S3 不是文件存储。

    【讨论】:

      猜你喜欢
      • 2015-07-17
      • 2016-07-25
      • 2018-11-18
      • 2020-07-01
      • 2016-11-12
      • 2019-11-09
      • 2020-06-06
      • 2021-11-11
      • 2020-02-27
      相关资源
      最近更新 更多