Docly Developers
Function API only Updated 29 Nov 2026

appendEmbeddedFile(filePath, embeddedId, data)

Appends bytes to the end of an embedded file in an existing Docly document, and creates the file on the first call.
Use it to store a file that is larger than one request can carry (API requests are limited to 30 MB). Send the file from the browser in chunks, one request at a time, and append each chunk to the same embedded file. The result is one embedded file that downloads as a whole from the editor.
Note that embedded files that are not referenced by a field in the document will be automatically deleted. Set the reference (for example with patchFile) when the last chunk is in place. A file that has been written to in the last few minutes is kept, so an upload in progress is not removed.

Parameters

filePathstringrequired

Absolute path to the document the embedded file belongs to. The document must be the site's own; a file that only exists in the app can't be changed (error 110).

embeddedIdstringrequired

Embedded file name. Must be at least 20 characters — use a GUID-based name so it is unique (error 9 otherwise). Use the same name for every chunk.

datastring or byte[]required

The chunk, as a base64 encoded string or an array of bytes. Send chunks of up to 16 MB as JSON; base64 makes the request a third larger.

Returns

Number, the size of the embedded file in bytes after the chunk is written. Compare it with the size you expect to check that the chunk arrived. Throws an error when the document is not found, when the document has no schema, when data is not base64 or a byte array, when the document is in an encrypted folder (error 10), or when another request is writing to the same file at the same time (error 11 — send the chunks one at a time). A chunk that fails is not partly written: the file keeps the size it had.

Example

Normal JavaScript, running in the browser or on the Docly™ server.
// API script, e.g. #/API/upload-chunk.js
// The browser posts { path, id, offset, data } as JSON: one chunk of up to 16 MB as base64.
// offset is where the chunk starts, so an interrupted upload can resume from the size the server reports.

let size = docly.getEmbeddedFileSize(form.path, form.id) || 0;
if (form.offset != size) {
    // The chunk doesn't continue the file - tell the browser where to resume
    docly.setResultCode(409);
    return { size: size };
}

let newSize = docly.appendEmbeddedFile(form.path, form.id, form.data);
return { size: newSize };

// When the last chunk is in place, reference the file in the document.
// The editor uses the <Field>_Filename value as the download name:
// docly.patchFile(form.path, { File: form.id, File_Filename: form.filename });