Event postCreate not fired after file upload

Hi,
I am trying to create a simple app to take action after a new file is uploaded so I created a simple code inside my Application.php

<?php

declare(strict_types=1);

namespace OCA\NotifyTest\AppInfo;

use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Events\Node\PostCreateEvent;

class Application extends App implements IBootstrap {
    public const APP_ID = 'notifytest';

    public function __construct() {
        parent::__construct(self::APP_ID);
    }

    public function register(IRegistrationContext $context): void {

    }

    public function boot(IBootContext $context): void {
        try {

            /** @var IEventDispatcher $dispatcher */
            $dispatcher = $context->getServerContainer()->get(IEventDispatcher::class);

            $dispatcher->addListener(PostCreateEvent::class, function (PostCreateEvent $event) use ($logPath): void {
                $node = $event->getNode();
                $path = $node->getPath();

                error_log("PostCreateEvent ausgelöst für: {$path}");
            });

            error_log('addListener für PostCreateEvent wurde erfolgreich registriert');
        } catch (\Throwable $e) {
            error_log('Fehler in boot(): ' . $e->getMessage());
        }
    }
}

``` The boot method is triggered but the event Listener gets not called after file upload does anybody has an idea what I am doing wrong?
The Event should be available at \OCP\Files: https://docs.nextcloud.com/server/stable/developer_manual/basics/events.html#ocp-event-dispatcher

Thanks

There’s no such event and therefore it’s not fired :wink:

Try your luck with NodeCreatedEvent.

2 Likes

Thanks for your reply with this Event it works!
And do you know how I can check if the current folder isShared with public user (email) there is a isShared() method in the Node class but it won’t work.
I call it like this

if (method_exists($node, 'isShared') && $node->isShared()) {

Thanks

I think you are looking for OCP\Share\IManager. For example getAccessList give you a list of all shares for a node.