Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Policy Condition failed: Setting policy in PostObjectV4

Tags:

php

amazon-s3

I'm trying to set Content-Disposition and Content-Type in PostObjectV4 but it fails. Following works fine:

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

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

But when I add the new parameters to $options it fails. I've tried only one of them and both of them. None of them works.

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

The errors are:

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

Link to option parameters: https://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.S3.Model.PostObject.html

like image 451
NicklasF Avatar asked Dec 17 '25 19:12

NicklasF


1 Answers

The issue was that $formInputs also had to be updated with the variables which wasn't clear.

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

$formInputs = [
    'key' => $key,
    'acl' => self::ACL,
    'Content-Type' => 'application/octet-stream'
];
like image 50
NicklasF Avatar answered Dec 19 '25 15:12

NicklasF



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!