SonataMediaBundle icon indicating copy to clipboard operation
SonataMediaBundle copied to clipboard

AmazonMetadataBuilder without setting fail

Open mpoiriert opened this issue 2 years ago • 0 comments

The AmazonMetadataBuilder is available as a service event if we don't configure the filesystem.s3.

The settings in that case will be empty.

The v4 rely on this setting to be present.

private function getDefaultMetadata(): array
{
    return [
        'ACL' => self::ACL[$this->settings['acl']],
        'storage' => self::STORAGE[$this->settings['storage']],
        'meta' => $this->settings['meta'],
        'CacheControl' => $this->settings['cache_control'],
        'encryption' => 'AES256',
    ];
}

In v3 check were made:

protected function getDefaultMetadata()
{
    //merge acl
    $output = [];
    if (isset($this->settings['acl'])) {
        $output['ACL'] = $this->acl[$this->settings['acl']];
    }

    //merge storage
    if (isset($this->settings['storage'])) {
        if ('standard' === $this->settings['storage']) {
            $output['storage'] = static::STORAGE_STANDARD;
        } elseif ('reduced' === $this->settings['storage']) {
            $output['storage'] = static::STORAGE_REDUCED;
        }
    }

    //merge meta
    if (isset($this->settings['meta'])) {
        $output['meta'] = $this->settings['meta'];
    }

    //merge cache control header
    if (isset($this->settings['cache_control'])) {
        $output['CacheControl'] = $this->settings['cache_control'];
    }

    //merge encryption
    if (isset($this->settings['encryption'])) {
        if ('aes256' === $this->settings['encryption']) {
            $output['encryption'] = 'AES256';
        }
    }

    return $output;
}

I have this issue since I am configuring my filesytem via a already existing service and the current implementation force usage of AmazonMetadataBuilder via the ProxyMetadataBuilder.

There is plenty of way to fix but I think this would be the best way: Check if the settings exists And Provide a way to easily configure it without relying on the s3 filesystem

mpoiriert avatar Jun 09 '22 16:06 mpoiriert