akamai / NetStorageKit-PHP

Akamai NetStorage for PHP
http://developer.akamai.com
Apache License 2.0
18 stars 19 forks source link

`403 Forbidden` response #16

Open supritha99games opened 3 years ago

supritha99games commented 3 years ago

Getting this 403 Forbidden response for the code - Trying to upload an image file to Akamai storage.

` $signer = new \Akamai\NetStorage\Authentication(); $signer->setKey($key, $keyName);

        $handler = new \Akamai\NetStorage\Handler\Authentication();
        $handler->setSigner($signer);

        $stack = \GuzzleHttp\HandlerStack::create();
        $stack->push($handler, 'netstorage-handler');

        $client = new \Akamai\Open\EdgeGrid\Client([
            'base_uri' => $host,
            'handler' => $stack,
        ]);

        $client->put('/' . $cpCode . '/Test', [
            'headers' => [
                'X-Akamai-ACS-Action' => 'version=1&action=upload&sha1=' .sha1($img)
            ],
            'body' => $img
        ]);`

Variable '$img' is the base64 decoded string of the image. '/Test' is the directory inside Akamai.

Error - "e":"Client error: PUT https://hostname/cpcode/Test resulted in a 403 Forbidden response","file":"/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php","line":113,"code":403

Formatted Output

Wanted few clarifications on usage of the above library -

  1. How to go about 403 Forbidden response?
  2. Where to mention the name of the image to be uploaded?
  3. How to give the image file path that exists on some other server to be uploaded to Akamai? (Instead of giving the file content)
francescjimenez commented 3 years ago

I think this should solve your issue: https://github.com/akamai/NetStorageKit-PHP/issues/17

The function that is signing the request is wrong. I solved it, and now is working correctly.