jeudi 27 août 2015

How to setup aws s3 key token to access object

I am using amazon s3 php sdk version 3

I am trying to create token or something by which I can make url which have access to object for that I have tried following code

$client = new Aws\S3\S3Client([
    'version' => 'latest',
    'region' => 'us-west-2',
    'credentials.ini' => [
        'key' => $credentials['key'],
        'secret' => $credentials['secret'],
    ],
]);

$bucket = 'demo-bucket';
$key = 'one.txt';
$SSECustomerKey = 'ra8mkasdf9';
$SSECustomerKeyMD5 = md5($SSECustomerKey);

$result = $client->putObject([
    'ACL' => 'authenticated-read',
    'Bucket' => $bucket, // REQUIRED
    'SSECustomerAlgorithm' => 'md5',
    'SSECustomerKey' => $SSECustomerKey,
    'SSECustomerKeyMD5' => $SSECustomerKeyMD5,
    'Key' => $key, // REQUIRED
]);

I am getting following error how to set argument which is valid as per aws because I think my argument is fine afaik

Fatal error: Uncaught exception 'Aws\S3\Exception\S3Exception' with message 'Error executing "PutObject" on "http://ift.tt/1Ua2Il0";

AWS HTTP error: Client error: 400 InvalidArgument (client): The calculated MD5 hash of the key did not match the hash that was provided. -

InvalidArgument : The calculated MD5 hash of the key did not match the hash that was provided.

and letter get object with those keys Now my question is how to set those keys and retrieve file using them ?




Aucun commentaire:

Enregistrer un commentaire