我正在尝试从 AWS 上的一个 S3 存储桶中获取所有图像 URL 的转储。我该怎么做?我一直在尝试下面的代码,但我不断收到错误's3.ServiceResource' object has no attribute 'generate_presigned_url'
,另一个问题是,如果我传递图像名称,此代码仅获取一张图像的 URL。我不想这样做,因为我希望图像为我的应用程序动态更改。
import boto3
s3 = boto3.resource('s3')
url = s3.generate_presigned_url('get_object',
Params={
'Bucket': 'mybucket',
'Key': 'upload/nocturnes.png',
},
ExpiresIn=3600)
print url
编辑:
此代码为我提供了存储桶中的密钥列表,但没有提供密钥的 URL。
import boto3
s3 = boto3.resource('s3')
my_bucket = s3.Bucket('bucket name')
for file in my_bucket.objects.all():
a= file.key
这对我有用。
import boto3
s3_client = boto3.client('s3')
s3_resource = boto3.resource('s3')
bucket_name = 'bucket_name'
my_bucket = s3_resource.Bucket(bucket_name)
for file in my_bucket.objects.all():
params = {'Bucket': bucket_name, 'Key': file.key}
url = s3_client.generate_presigned_url('get_object', params)
print url
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句