fileproxy-client
, (*1)
A client library for fileproxy, (*2)
Quickstart
composer require ipunkt/fileproxy-client
Usage
Setting up our client., (*3)
$client = new \Guzzle\Http\Client();
$fileproxy = new \Ipunkt\Fileproxy\FileproxyClient('https://file-proxy.app', $client);
Setting Credentials
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, (*4)
$fileproxy->setCredentials('S3cr3T');
Or, you can configure another header name than the default one:, (*5)
$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:, (*6)
$fileproxy->addHeader('X-HEADER', 'custom value');
Files resource
Files resource handles all stuff with the related proxy files. These files are the source for the aliases provided by the service., (*7)
Uploading a new file
$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., (*8)
Updating an uploaded file
$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., (*9)
Storing a remote file
$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., (*10)
Updating a stored remote file
$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., (*11)
Requesting a file by 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., (*12)
FileAlias resource
You can create or retrieve aliases with this resource., (*13)
Creating an alias
/** @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., (*14)
Fetching all aliases
/** @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
., (*15)
Alias resource
Alias resource handles requesting and deleting of aliases., (*16)
Requesting an alias
/** @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., (*17)
Deleting an alias
$fileproxy->alias()->delete($aliasId);// $aliasId = "${reference}.${alias}"
Alias was deleted when no exception was thrown., (*18)
Statistics resource
Requesting statistics
/** @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., (*19)