Saving file

The reference figure and the steps below explain the process of saving the document in ONLYOFFICE Document Server.

Opening File
  1. The user edits the document in the document editor.
  2. The document editor sends the changes to the document editing service.
  3. The user closes the document editor.
  4. The document editing service watches the end of work with the document and collects the changes send from the document editor into one document.
  5. The document editing service informs the document storage service about the end of the document editing using the callbackUrl from JavaScript API and returns the link to the modified document.
  6. The document storage service downloads the document file with all the saved changes from the document editing service and stores it.
  1. Create a callback handler to save the document from document editing service.
  2. Create an html file to Open the document.
  3. In the configuration script for Document Editor initialization specify the URL to the file with the Callback handler in the parameter line.
    new DocsAPI.DocEditor("placeholder", {
        "document": {
            "fileType": "docx",
            "key": "Khirz6zTPdfd7",
            "title": "Example Document Title.docx",
            "url": "http://example.com/url-to-example-document.docx"
        },
        "documentType": "text",
        "editorConfig": {
            "callbackUrl": "http://example.com/url-to-callback.ashx"
        }
    });
    
    Where the example.com is the name of the the server where document manager and document storage service are installed.
  4. Open your html file in the browser and edit your document.
  5. Close the Document Editor. Check out your document in about 10 seconds. All changes should be saved, meaning the configuration is correct.

The document editing service informs the document storage service about the end of the document editing after 10 seconds of editing closure. The time is not precise and is calculated using the file conversion time and conversion start delay time. The duration of the edited file conversion into the Office Open XML format depends on the file structure complexity and can be performed rather a long time. The conversion start delay is necessary to allow to return to the file editing session without the file saving, e.g. when reloading the browser page with the file opened for editing. The conversion start delay time can be changed in Document Server configuration file, which can be found at the following path:

For Linux - /etc/onlyoffice/documentserver/default.json.
For Windows - %ProgramFiles%\ONLYOFFICE\DocumentServer\config\default.json.
Parameters
Parameter Description Type Example
services.CoAuthoring.server.savetimeoutdelay Defines the conversion start delay time (in milliseconds) after the edited file is closed. integer 5000
Sample default.json configuration
{
    "services": {
        "CoAuthoring": {
            "server": {
                "savetimeoutdelay": 5000
            }
        }
    }
}

Document editing service allows to get the current document state before the editing is finished. The process is called forcesave in ONLYOFFICE Document Server. When forcesave is initiated, document editing service performs request to the callback handler with the link to the document as the url parameter and with the 6 value for the status parameter. The forcesave process can be initiated the following ways:

  • By the request to the document command service with the forcesave value in the c parameter. The forcesavetype parameter will have the 0 value when sending the request to the callback handler.
  • Enable the editorConfig.customization.forcesave mode setting it to true in the editor initialization configuration. In this case each time the user clicks the Save button, the forcesave will be done, and the forcesavetype parameter will have the 1 value when sending the request to the callback handler.
  • You can enable the repeating forcesave start in the Document Server configuration file, which can be found at the following path:
    For Linux - /etc/onlyoffice/documentserver/default.json.
    For Windows - %ProgramFiles%\ONLYOFFICE\DocumentServer\config\default.json.
    Parameters
    Parameter Description Type Example
    services.CoAuthoring.autoAssembly.enable Specifies enabling the repeating force saving. The default value is false. boolean false
    services.CoAuthoring.autoAssembly.interval Defines the time interval in minutes for initializing the force save. string 5m
    Sample default.json configuration
    {
        "services": {
            "CoAuthoring": {
                "autoAssembly": {
                    "enable": true,
                    "interval": "5m"
                }
            }
        }
    }
    
    The forcesavetype parameter will have the 2 value when sending the request to the callback handler.