metadataflysystemthephpleague

league/flysystem-aws-s3-v3 get custom metada


I'm messing with the flysystem library (it is amazing, anyway!) I created some files on the remote s3 bucket defining some custom metadata

$conf = [
'visibility' => 'public',
'Metadata'     => [
    'Content-type' => 'image/jpeg',
    'Generated' => 'true'
]];
$response = $filesystem->write('/test/image.jpg', $image_stream, $conf);

'Generated' => 'true' is a custom metadata and I can find it in AWS Bucket's console.

I'm not able to read the custom metadata "generated" on filesystem resource after

$allFiles = $filesystem->listContents('/path/', true)->toArray();

##UPDATE 1

I understood that I should use the "getWithMetadata" plugin as explained In the documentation: https://flysystem.thephpleague.com/v1/docs/advanced/provided-plugins/#get-file-info-with-explicit-metadata

It seems pretty easy, but it seems there is not any League\Flysystem\Filesystem::addPlugin() method in my src.

Can anybody help me?


Solution

  • to use the S3 FlySystem adapter you need to init the S3 client

    $client = new Aws\S3\S3Client($options);
    

    In S3 SDK you could use

    $allFiles = $filesystem->listContents($path)->sortByPath()->toArray();
    
    $file = $allFiles[0];
    $headers = $client->headObject(array(
    "Bucket" => $bucket,
    "Key" => $file->path()
    ));
    
    print_r($headers->toArray());
    

    to get the list of all file's metadata!