Skip to content

External storages PRO

Support for uploading transforms to external services has been structured into what's called Storages, handled through the storages and storageConfig config settings. There are three first-party storage plugins available:

PluginHandleComposer package
Imager X AWS Storage Driverawsspacecatninja/imager-x-aws-storage-driver
Imager X GCS Storage Drivergcsspacecatninja/imager-x-gcs-storage-driver
Imager X DO Spaces Driverdospacesspacecatninja/imager-x-do-spaces-driver

TIP

In Imager X 6.0, the AWS S3 and Google Cloud Storage drivers were extracted from the core plugin into their own separate plugins. If you are upgrading from 5.0, install the plugin(s) you need via composer.

Use storages to specify which storage(s) to upload to, and configure each in storageConfig:

php
'imagerUrl' => 'https://my-bucket.s3.eu-west-1.amazonaws.com/transforms/',
'storages' => ['aws'],
'storageConfig' => [
    'aws' => [
        'accessKey' => 'MY_ACCESS_KEY',
        'secretAccessKey' => 'MY_SECRET_KEY',
        'region' => 'eu-west-1',
        'bucket' => 'my-bucket',
        'folder' => 'transforms',
        'storageType' => 'standard',
        'requestHeaders' => [],
        'disableACL' => false,
        'cloudfrontInvalidateEnabled' => false,
        'cloudfrontDistributionId' => '',
    ],
    'gcs' => [
        'keyFile' => '/var/secrets/gcs-key.json',
        'bucket' => 'my-bucket',
        'folder' => 'transforms',
    ],
    'dospaces' => [
        'endpoint' => 'https://ams3.digitaloceanspaces.com',
        'accessKey' => 'MY_ACCESS_KEY',
        'secretAccessKey' => 'MY_SECRET_KEY',
        'region' => 'ams3',
        'bucket' => 'my-bucket',
        'folder' => 'transforms',
        'requestHeaders' => [],
    ],
],

Additional storages can be created by implementing the ImagerStorageInterface, and registering your class using the ImagerService::registerExternalStorage method, like so:

php
ImagerService::registerExternalStorage('aws', AwsStorage::class);

TIP

Configuring an external storage doesn't mean that transforms will automatically be served from that location — you still need to set imagerUrl appropriately. The transformed images are still kept in your imagerSystemPath and used for caching purposes.

Copyright © 2024 André Elvan