2使用boto3将这些网址发布到S3

时间:2017-03-31 09:00:40

标签: python-2.7 amazon-s3 boto3

我正在尝试使用boto3生成2个后果,按下帖子以发布到S3。这个网址我回到用户发布2个语义不同的文件连接文件。

full_ecs_xsd_key = 'txn/jackalope/edispec/TPD/local/opikovets/my_test_file_3'

fields = {
    "x-amz-meta-identity-id": user_id,
    "x-amz-server-side-encryption": "AES256"
}
conditions = [
    {"x-amz-meta-identity-id": user_id},
    {"x-amz-server-side-encryption": "AES256"}
]

xsd_key = full_ecs_xsd_key + '.xsd'
pre_signed_xsd_post_url = copy.deepcopy(s3_client.generate_presigned_post(
    bucket_name, xsd_key,
    Fields=fields,
    Conditions=conditions
))

ecs_key = full_ecs_xsd_key + '.ecs'
pre_signed_ecs_post_url = copy.deepcopy(s3_client.generate_presigned_post(
    bucket_name, ecs_key,
    Fields=fields,
    Conditions=conditions
))

因此,我得到2个似乎正在工作的网址,但我无法将数据发布到第二个网址(pre_signed_ecs_post_url)。收到错误

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>AccessDenied</Code>
    <Message>Invalid according to Policy: Policy Condition failed: ["eq", "$key", "txn/jackalope/edispec/TPD/local/opikovets/my_test_file_3.xsd"]</Message>
    <RequestId>1343F7E406E82C1A</RequestId>
    <HostId>wm0U14OouoMkbm0bWIqkYDtP7fgR2A+0Q/Mvhvo9sJ7paaXDiMWfqnjCMR4mc5euPcXCyP3u2/w=</HostId>
</Error>

这里令人困惑的是,错误中显示的键实际上是第一个url的键,而不是第二个url的键。所以,我认为当我第一次调用generate_presigned_post时,它会创建一个类的实例,该类也用于创建第二个URL ...

但这只是猜测,我不知道如何解决这个特殊问题

1 个答案:

答案 0 :(得分:1)

Per @ Michael-sqlbot评论fieldsconditionsgenerate_presigned_post()执行期间发生了变化,因此我将呼叫更改为:

ecs_key = full_ecs_xsd_key + '.ecs'
pre_signed_ecs_post_url = s3_client.generate_presigned_post(
    bucket_name, ecs_key,
    Fields=copy.deepcopy(fields),
    Conditions=copy.deepcopy(conditions)
)

xsd_key = full_ecs_xsd_key + '.xsd'
pre_signed_xsd_post_url = s3_client.generate_presigned_post(
    bucket_name, xsd_key,
    Fields=copy.deepcopy(fields),
    Conditions=copy.deepcopy(conditions)
)

并且一切正常