KnpLabs / Gaufrette

PHP library that provides a filesystem abstraction layer − will be a feast for your files!

Home Page:http://knplabs.github.io/Gaufrette

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to update metadata of file in GridFS

averichev opened this issue · comments

Please, tell me, how i can update file metadata after write.

my code

$gridFSAdapter->write($fileName, $file->getContent());
$gridFSAdapter->setMetadata($fileName, [
    'mimeType' => $uploadedFile->getMimeType(),
    'clientOriginalExtension' => $uploadedFile->getClientOriginalExtension(),
    'clientOriginalName' => $uploadedFile->getClientOriginalName(),
    'uploadUserId' => $this->getUser()->getId(),
]);

@NiR- ?

Hello,

From the gridFS code, the setMetadata function only stores it in memory : https://github.com/KnpLabs/Gaufrette/blob/master/src/Gaufrette/Adapter/GridFS.php#L153-L159

you have to call write to persist the metadata on the storage : https://github.com/KnpLabs/Gaufrette/blob/master/src/Gaufrette/Adapter/GridFS.php#L51-L65

so, with your snippet :

$gridFSAdapter->getMetadata($key , $value);
$gridFSAdapter->write($key, $content);