2
votes

I have a bucket created in ap-southeast-1 region with ACL set to private-read. I am able to successfully upload files to folders inside the bucket using the AWS PHP SDK 2 S3Client class. However, I also need to display a link to these files in my application. Hence, when a user clicks a button, I send an AJAX request to my server file, and I get the signedURL which is returned back to the user via json string. However, the url always returns with an XML with error SignatureDoesNotMatch.

Code for getting the signedURL below:

 //create the AWS reference string
    $client = S3Client::factory(
                             array(
                                'key'    => T_AWS_KEY,
                                'secret' => T_AWS_SECRET,
                                'region' => T_BASE_REGION
                                )
                             );
    //method 1  - using Command Object

    $command = $client->getCommand('GetObject', array(
        'Bucket' => T_BASE_BUCKET . "/" . $firmId . "/invoices" ,
        'Key' => $arr['file_reference_url'] ,
        'ResponseContentDisposition' => 'attachment;filename=' . arr['file_reference_url']
    ));

    $signedUrl = $command->createPresignedUrl('+10 minutes');
    echo $signedUrl . "\n\n";

    //method 2 - using getObjectUrl
    echo $client->getObjectUrl(T_BASE_BUCKET . "/" . $firmId .  "/invoices", $arr['file_reference_url'], "+10 minutes");

Any help is appreciated.

1

1 Answers

1
votes

It seems you may be confused about what buckets are. Buckets are not nested. It's likely that the value of T_BASE_BUCKET is your bucket and the other parts are part of the object key. Give this a shot:

$objectKey = $firmId . '/invoices/' . $arr['file_reference_url'];
echo $client->getObjectUrl(T_BASE_BUCKET, $objectKey, '+10 minutes');