PHP code example of akamai-open / netstorage

1. Go to this page and download the library: Download akamai-open/netstorage library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

akamai-open / netstorage example snippets


$signer = new Akamai\NetStorage\Authentication();
$signer->setKey($key, $keyName);
$signer->setPath('/' .$cpCode. '/path/to/file');
$signer->setAction('upload');
$headers = $signer->createAuthHeaders();

/*
Return:
[
    'X-Akamai-ACS-Auth-Data' => $authData,
    'X-Akamai-ACS-Auth-Sign' => $signature
];
*/

$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
]);

// Upload a file:
// Request signature is added transparently
// All parent directories must exist (e.g. /path/to)
$client->put('/' . $cpCode . '/path/to/file', [
    'headers' => [
        'X-Akamai-ACS-Action' => 'version=1&action=upload&sha1=' .sha1($fileContents)
    ],
    'body' => $fileContents
]);

$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
]);

$adapter = new \Akamai\NetStorage\ObjectStoreAdapter($client, $cpCode);
$fs = new \League\Flysystem\Filesystem($adapter);

// Upload a file:
// cpCode, action, content signature, and request signature is added transparently
// Additionally, all