获取权限错误:[Erno 13]上传到s3时权限被拒绝



当我尝试使用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 

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

@Marcin是对的。

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

最新更新