策略条件失败:在PostObjectV4中设置策略

时间:2018-12-21 14:07:59

标签: php amazon-s3

我试图在PostObjectV4中设置Content-Disposition和Content-Type,但是失败。以下工作正常:

$options = [
   ['bucket' => $bucket],
   ['acl' => self::ACL],
   ['key' => $key]
];

$postObject = new PostObjectV4(
   $client,
   $bucket,
   $formInputs,
   $options,
   $expires
);

但是当我将新参数添加到$ options时,它将失败。我只尝试了其中一个,也尝试了两个。它们都不起作用。

$options = [
    ['bucket' => $bucket],
    ['acl' => self::ACL],
    ['key' => $key],
    ['Content-Type' => 'application/octet-stream'],
    ['Content-Disposition' => 'attachment']
];

错误是:

Invalid according to Policy: Policy Condition failed: ["eq", "$Content-Type", "application/octet-stream"]
Invalid according to Policy: Policy Condition failed: ["eq", "$Content-Disposition", "attachment"]

链接到选项参数:https://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.S3.Model.PostObject.html

1 个答案:

答案 0 :(得分:0)

问题在于$ formInputs还必须使用不清楚的变量进行更新。

$options = [
    ['bucket' => $bucket],
    ['acl' => self::ACL],
    ['key' => $key],
    ['Content-Type' => 'application/octet-stream']
];

$formInputs = [
    'key' => $key,
    'acl' => self::ACL,
    'Content-Type' => 'application/octet-stream'
];