我正在尝试使用boto3创建预先签名的帖子签名和表单。
key = str(venuepk) +'/' + str(samplemenuid) + '/${filename}'
fields = {'acl': 'public-read',
'content-type': 'application/PDF'}
conditions = {'acl': 'public-read',
'content-type': 'application/PDF'}
s3=boto3.client('s3')
post = s3.generate_presigned_post(
Bucket = AWS_UPLOAD_BUCKET,
Key = key,
Fields = fields,
Conditions=conditions
)
return Response({
'url': post['url'],
'fields': post['fields'],
'samplemenupk': samplemenuid
})
跟随文档到'T'
https://boto3.readthedocs.io/en/latest/guide/s3.html#generating-presigned-posts
但我一直收到这个错误:
File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/virtualsuits/local/lib/python2.7/site-packages/rest_framework/views.py", line 491, in dispatch
response = handler(request, *args, **kwargs)
File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/virtualsuits/suitsandtables/venues/views.py", line 142, in post
Conditions=conditions
File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/virtualsuits/local/lib/python2.7/site-packages/botocore/signers.py", line 698, in generate_presigned_post
conditions.append({'bucket': bucket})
AttributeError: 'dict' object has no attribute 'append'
答案 0 :(得分:0)
错误是因为python dicts没有附加方法。条件值应该是一个列表,如下所示
conditions = [
{"acl": "public-read"},
["content-length-range", 10, 100]
]
它实际上显示为documentation
中的列表