live-controls/storage

There is no license information available for the latest version (v1.3.12) of this package.

Object Storage Library for live-controls

v1.3.12 2024-10-19 22:59 UTC

README

Release Version Packagist Version

Object Storage Library for live-controls

Requirements

  • PHP 8.0+
  • S3 compatible Object Storage Hoster like Contabo or DigitalOcean

Translations

None

Installation

composer require live-controls/storage

Setup FluentObjectStorageHandler

  1. If you want to use DBDisks, create the migration like this:
php artisan vendor:publish --provider="LiveControls\Storage\StorageServiceProvider" --tag="migrations"

Setup ObjectStorageHandler

  1. Add to .env:
OBJECTSTORAGE_ACCESS_KEY_ID=53234123 //Should be the access key id to the storage
OBJECTSTORAGE_SECRET_ACCESS_KEY=0000000 //Should be the secret access key to the storage
OBJECTSTORAGE_DEFAULT_REGION=usc1 //Should match the subdomain in endpoint or url
OBJECTSTORAGE_BUCKET=bucketName //The name of the bucket
OBJECTSTORAGE_URL=https://usc1.contabostorage.com/1234567890:bucketName //The url of the bucket
OBJECTSTORAGE_ENDPOINT=https://usc1.contabostorage.com/ //The endpoint of the bucket
OBJECTSTORAGE_USE_PATH_STYLE_ENDPOINT=true //Needs to be true to work!
  1. Add to config/filesystems.php:
'disks' => [
     ...
   'objectstorage' => [
       'driver' => 's3',
       'key' => env('OBJECTSTORAGE_ACCESS_KEY_ID'),
       'secret' => env('OBJECTSTORAGE_SECRET_ACCESS_KEY'),
       'region' => env('OBJECTSTORAGE_DEFAULT_REGION'),
       'bucket' => env('OBJECTSTORAGE_BUCKET'),
       'url' => env('OBJECTSTORAGE_URL'),
       'endpoint' => env('OBJECTSTORAGE_ENDPOINT'),
       'use_path_style_endpoint' => env('OBJECTSTORAGE_USE_PATH_STYLE_ENDPOINT', false),
       'throw' => false,
   ],
]
  1. Publish configuration file with:
php artisan vendor:publish --tag="livecontrols.storage.config"
  1. Set "storage:disk" to the name of your disk set in Step 2

Usage

Todo

Hint

  • To use it with big files, use fopen($fName, 'r+') and not file_get_contents($fName)
  • If you are, for whatever reason, need to change the directory separator to something else than a forwards slahs, change the "directory_separator" inside the configuration file. But you normally wouldn't want to do this, because it would break the temporaryUrl return value.