entityManager->getEntityById(Attachment::ENTITY_TYPE, $id); if (!$attachment) { return null; } try { $this->checker->checkTypeImage($attachment); } catch (Forbidden) { return null; } $type = $attachment->getType(); if (!$type) { return null; } $contents = $this->fileStorageManager->getContents($attachment); return 'data:' . $type . ';base64,' . base64_encode($contents); } }