dbp / relay-blob-library
PHP helper library for interaction with the relay-blob-bundle.
Installs: 22 548
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 1
Requires
- php: >=8.1
- ext-json: *
- guzzlehttp/guzzle: ^7.0
- web-token/jwt-library: ^3.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.50
- phpstan/phpstan: ^1.10.59
- phpstan/phpstan-phpunit: ^1.3.16
- phpstan/phpstan-symfony: ^1.3.7
- phpunit/phpunit: ^9.6.17
- symfony/browser-kit: ^5.4.35
- symfony/http-client: ^5.4.36
- symfony/phpunit-bridge: ^5.4.36
- vimeo/psalm: ^5.22.2
README
GitHub | Packagist | Changelog
PHP helper library for interaction with the relay-blob-bundle.
Installation
composer require dbp/relay-blob-library
Usage
use Dbp\Relay\BlobLibrary\Api\BlobApi; use Dbp\Relay\BlobLibrary\Api\BlobApiError; // The blob base url is the url of your API server where the relay-blob-bundle is installed $blobBaseUrl = 'https://api.your.server'; // See https://github.com/digital-blueprint/relay-blob-bundle#configuration for more information about the blob bucket id and key $blobBucketId = 'your-bucket-id'; $blobKey = 'your-blob-key'; // Create a new BlobApi instance $blobApi = new BlobApi($blobBaseUrl, $blobBucketId, $blobKey); $prefix = 'my-prefix'; $fileName = 'my-file-name.pdf'; $fileData = 'my-binary-file-data'; // oauth specific variables // replace with your own config $oauthIDPUrl = 'https://your.oauth.server'; // oauthIDP url including realm $clientID = 'your-client-id'; $clientSecret = 'your-client-secret'; // if needed, get an OAuth2 token try { $blobApi->setOAuth2Token($oauthIDPUrl, $clientID, $clientSecret); } catch (BlobApiError $e) { // Handle error, print $e->getMessage() for more information } // Upload a file to the blob storage and get the identifier try { $identifier = $blobApi->uploadFile($prefix, $fileName, $fileData); } catch (BlobApiError $e) { // Handle error var_dump($e->getMessage()); var_dump($e->getErrorId()); var_dump($e->getErrorDetails()); } // Download a file from the blob storage by identifier and get the content url try { // The content url is a data url and looks for example like this: // data:application/pdf;base64,JVBERi0xLjUKJbXtrvsKNCAwIG9iago....= $contentUrl = $blobApi->downloadFileAsContentUrlByIdentifier($identifier); } catch (BlobApiError $e) { // Handle error, print $e->getMessage() for more information } // Delete a file from the blob storage by identifier try { $blobApi->deleteFileByIdentifier($identifier); } catch (BlobApiError $e) { // Handle error, print $e->getMessage() for more information } // Delete all files from the blob storage by prefix try { $blobApi->deleteFilesByPrefix($prefix); } catch (BlobApiError $e) { // Handle error, print $e->getMessage() for more information }
- For more usage examples, see examples
- For more information about the API, see api.md
- For information about error codes, see error-codes.md