https://github.com/ipunkt/fileproxy-client
A client library for fileproxy
https://github.com/ipunkt/fileproxy-client
Last synced: 5 months ago
JSON representation
A client library for fileproxy
- Host: GitHub
- URL: https://github.com/ipunkt/fileproxy-client
- Owner: ipunkt
- License: mit
- Archived: true
- Created: 2017-05-04T05:57:01.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-05-24T14:50:48.000Z (about 8 years ago)
- Last Synced: 2025-06-15T18:05:37.668Z (about 1 year ago)
- Language: PHP
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fileproxy-client
[](https://packagist.org/packages/ipunkt/fileproxy-client) [](https://packagist.org/packages/ipunkt/fileproxy-client) [](https://packagist.org/packages/ipunkt/fileproxy-client) [](https://packagist.org/packages/ipunkt/fileproxy-client)
A client library for fileproxy
## Quickstart
```
composer require ipunkt/fileproxy-client
```
## Usage
Setting up our client.
```php
$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
```php
$fileproxy->setCredentials('S3cr3T');
```
Or, you can configure another header name than the default one:
```php
$fileproxy->setCredentials('S3cr3T', 'X-ANOTHER-SECURITY-TOKEN-NAME');
```
### Setting Headers
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:
```php
$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.
#### Uploading a new file
```php
$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.
#### Updating an uploaded file
```php
$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.
#### Storing a remote file
```php
$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.
#### Updating a stored remote file
```php
$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.
#### Requesting a file by reference
```php
/** @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.
### FileAlias resource
You can create or retrieve aliases with this resource.
#### Creating an alias
```php
/** @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.
#### Fetching all aliases
```php
/** @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
Alias resource handles requesting and deleting of aliases.
#### Requesting an alias
```php
/** @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.
#### Deleting an alias
```php
$fileproxy->alias()->delete($aliasId);// $aliasId = "${reference}.${alias}"
```
Alias was deleted when no exception was thrown.
### Statistics resource
#### Requesting statistics
```php
/** @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.