A client library for fileproxy
composer require ipunkt/fileproxy-client
Setting up our client.
$client = new \Guzzle\Http\Client();
$fileproxy = new \Ipunkt\Fileproxy\FileproxyClient('https://file-proxy.app', $client);
Since version 1.1.0 the fileproxy has the ability to protect api calls with a secret token header. You can add that to the client like so
$fileproxy->setCredentials('S3cr3T');
Or, you can configure another header name than the default one:
$fileproxy->setCredentials('S3cr3T', 'X-ANOTHER-SECURITY-TOKEN-NAME');
Another security level can be added by adding custom http headers for each request. So your infrastructure can verify the request by parsing them. You can achieve this like so:
$fileproxy->addHeader('X-HEADER', 'custom value');
Files resource handles all stuff with the related proxy files. These files are the source for the aliases provided by the service.
$fileToUpload = new \SplFileInfo('/absolute/file/path.ext');
/** @var \Ipunkt\Fileproxy\Entities\File $file */
$file = $fileproxy->files()->store($fileToUpload);
$file
is a File entity with the main information about the file itself - the reference.
$reference = 'UUID-FROM-LOCAL-STORAGE';
$fileToUpload = new \SplFileInfo('/absolute/file/path.ext');
/** @var \Ipunkt\Fileproxy\Entities\File $file */
$file = $fileproxy->files()->update($reference, $fileToUpload);
$file
is a File entity with the main information about the file itself - the reference.
$url = 'https://domain.tld/images/picture.jpg';
/** @var \Ipunkt\Fileproxy\Entities\File $file */
$file = $fileproxy->files()->storeRemote($url);
$file
is a File entity with the main information about the file itself - the reference.
$reference = 'UUID-FROM-LOCAL-STORAGE';
$url = 'https://domain.tld/images/picture.jpg';
/** @var \Ipunkt\Fileproxy\Entities\File $file */
$file = $fileproxy->files()->updateRemote($reference, $url);
$file
is a File entity with the main information about the file itself - the reference.
/** @var \Ipunkt\Fileproxy\Entities\File $file */
$file = $fileproxy->files()->get($reference);// $reference is a UUID4
$file
is a File entity. You can fetch the hits from it for example.
You can create or retrieve aliases with this resource.
/** @var \Ipunkt\Fileproxy\Entities\Alias $alias */
$alias = $fileproxy->fileAliases($reference /* only once needed */)->create('limited-file.jpg', 5 /* hits only */);// $reference is a UUID4
The created $alias
will be returned and includes the download url and the alias id.
/** @var \Ipunkt\Fileproxy\Entities\Alias[]|array $aliases */
$aliases = $fileproxy->fileAliases($reference /* only once needed */)->all();// $reference is a UUID4
You can iterate over all existing $aliases
.
Alias resource handles requesting and deleting of aliases.
/** @var \Ipunkt\Fileproxy\Entities\Alias $alias */
$alias = $fileproxy->alias()->get($aliasId);// $aliasId = "${reference}.${alias}"
$alias
is an Alias entity. The main information about an alias is the download url and the hits and hits left statistics data.
$fileproxy->alias()->delete($aliasId);// $aliasId = "${reference}.${alias}"
Alias was deleted when no exception was thrown.
/** @var \Ipunkt\Fileproxy\Entities\Statistic $stats */
$stats = $fileproxy->statistics()->stats();
$stats
returns the main statistics for the current service: size in bytes, file and alias count serving and hits summarized.