getting PermissionError: [Errno 13] Permission denied while uploading to s3
getting PermissionError: [Errno 13] Permission denied while uploading to 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 buckets的结构也很关键。因为s3是对象存储,所以它其实是没有文件夹结构的。
您在存储桶中创建的文件夹只是按文件名可视化分组的对象,如 /**folder**/myfile.pdf
。
这样做是为了让我们可以更轻松地与对象进行交互。
但是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 buckets的结构也很关键。因为s3是对象存储,所以它其实是没有文件夹结构的。
您在存储桶中创建的文件夹只是按文件名可视化分组的对象,如 /**folder**/myfile.pdf
。
这样做是为了让我们可以更轻松地与对象进行交互。
但是S3不是文件存储。