Best Practices for Handling status callback with same doc keys

I am integrating ONLYOFFICE into my system to embed it in a React app. For backend operations, I am handling the status callback as per the documentation (Callback Handler) and have S3 configured as the document cache.

Here’s the challenge:

  1. When receiving a status 2 callback, I need to update the document with the modified one provided in the url parameter. Ideally, I should create a new version of the document and pass ONLYOFFICE a new document key for subsequent editing sessions.
  2. Currently, we are not handling document versions in our system. Instead, we overwrite the existing document and reuse the same document key. This causes problems when returning to the editor.

To work around this, I attempted to clear the S3 document cache (deleting the file from S3) upon receiving status 2. However, this approach results in the following error when reopening the document for a second editing session: “An error has occurred while opening the file.”

Questions:

  1. What is the recommended way to handle document keys in this scenario?
  2. Is there a proper way to manage overwriting documents without changing the document key or implementing full version control?
  3. If clearing the S3 cache is the correct approach, what additional steps are needed to avoid the error when reopening the document?

I would appreciate any guidance or best practices for solving this issue, thanks!

Hello @leandro

What exactly happens?

This is definitely bad practice. Please take a look at the description of document.key parameter:

Defines the unique document identifier used by the service to recognize the document. In case the known key is sent, the document will be taken from the cache. Every time the document is edited and saved, the key must be generated anew.

So using the same key means that Document Server will use the file from cache instead of downloading the document again, which simply preserves time. When you are removing folder from cache, Document Server cannot locate it and open file, hence returns an error, because information about recently opened files is stored in the PostgreSQL database, which is also used to control cache content.

Basically, you need to generate new keys for documents once they are completely closed (no editing sessions has left and nobody edits them). Also, you need to preserve the key during collaborative editing so that users will be able to open the same document instead of creating a copy of it in cache.

If you are looking for any examples, you can download, install and analyze test examples.

@Constantine When returning to the editor after overwrite the existing document and reuse the same document key this is what happens:

Is there any workaround we can do? because creating new document keys whenever a editing session finished, right now for us implies a lot of changes in our side which will prevent us from using Onlyoffice

Thanks!

I’m afraid this is how editing service works. Please see the troubleshooting page:
https://api.onlyoffice.com/docs/docs-api/more-information/troubleshooting/#the-file-version-has-been-changed

Once editing session has been terminated and file was saved to the storage, you cannot re-use old key and need to generate new one for a new session of editing.

I will simply concatenate our document ID with our internal last_updated_at timestamp to pass as key, so you can mark this ticket as solved.

Thanks!

1 Like