当使用AWS S3上传文件夹时,如果指定的键不存在,会出现“AWS S3 - 指定的键不存在 - 用于上传的文件夹”的错误。这种错误通常是因为指定的键路径在S3桶中不存在导致的。解决此问题的方法如下:
import boto3
s3 = boto3.resource('s3')
bucket_name = 'your-bucket-name'
key = 'your-key'
bucket = s3.Bucket(bucket_name)
objects = list(bucket.objects.filter(Prefix=key))
if len(objects) > 0:
print('Key exists')
else:
print('Key does not exist')
import boto3
s3 = boto3.resource('s3')
bucket_name = 'your-bucket-name'
key = 'your-key'
bucket = s3.Bucket(bucket_name)
bucket.put_object(Key=key)
print('Key created')
通过上述两种方法,您可以解决“AWS S3 - 指定的键不存在 - 用于上传的文件夹”错误,并成功上传文件夹到指定的S3桶中。