Preview not updated after replacing PDF content via putContent()

Hi everyone,

I am currently implementing a webhook-based integration that stores signed PDF documents in Nextcloud. The integration replaces the content of an existing file after it has been signed.

I am using the following code:

$userFolder = $this->rootFolder->getUserFolder($userId);
$files = $userFolder->getById($fileId);

if (empty($files)) {
    throw new OCSBadRequestException($fileId . ' File not found');
}

$file = $files[0];

// Replace content with signed PDF
$file->putContent($signedPdfContent);
$file->touch();

The Problem

The file content is correctly replaced (downloading the file shows the signed version), but the preview in the Nextcloud web interface is not updated.

The preview still shows the old (unsigned) version of the PDF even after some time has passed.

What I Already Tried

Calling $file->touch() after putContent()

Forcing a modified time offset using $file->touch(time() + 180);

Touching the parent folder as well

Important Requirements

The file should keep its file ID and version history

We don’t want to delete and recreate the file

The preview should update immediately / shortly after replacing the content

Questions

Is there a recommended way to invalidate or regenerate previews programmatically after calling putContent()?

Is there an internal API for clearing preview cache for a specific file?

Is this expected behavior due to preview caching, and if so, what is the correct way to handle it?

Any guidance would be greatly appreciated.

Thank you!