saveFile(filePath, data, [options]) Last updated: 17. Jul 2026

API only function

Saves a file to a Docly document according to specified schema. Overwrites if it already exists.

See also: getFile getFiles getJson fileExists Path traversal

Parameters

Name Type Description
filePath string

Absolute path to where you want to save data, WITHOUT the .docly extension — it is appended for you. Passing "#/queue/item.docly" produces "item.docly.docly".

data object

Data to store, will be converted to JSON and stored.

options (optional)objectSpecify any of the following options parameters:
schema string

Absolute path to your Docly schema to store the file as, WITHOUT the .docly extension — e.g. "#/Schema/Invoice", not "#/Schema/Invoice.docly".
Required for new files, for updating existing file it is not required.
You can also reference the schema by document hash (#Dxxxx).

ensurePath bool

If true the folder path will be created if it is missing.
Default is false.

embedBase64 bool

If true, base64-encoded content in the data will be extracted and stored as separate embedded attachments, referenced via CID links in the saved document. This reduces document size and improves performance for binary content like images or files. Default is false.

Returns

An object with references to the saved file with:

  • timestamp
  • guid
  • filename
  • Filename may be needed if autogenerated filenames are used.

Example

Code example (#JS)

#JS is mixed HTML (or other text file) with inline JavaScript with # starting and ending each inline statement.
// Note: both paths are extensionless. saveFile appends .docly itself.
let result = saveFile("#/queue/item-001", { Name: "Ada", Message: "Hello" }, {
    schema: "#/Schema/Feedback",   // NOT "#/Schema/Feedback.docly"
    ensurePath: true
});

return result;   // { timestamp, guid, filename }

For a fuller example see:
[Save data to Docly from API function](/JavaScript/Examples/Data/Save-data-to-Docly-from-API-function)