Docly Developers
Function API only Updated 15 Oct 2026

saveEmbeddedFile(filePath, embeddedId, data)

Saves an embedded file to an existing Docly document.
Note that embedded files that are not referenced by a field in the document will be automatically deleted.

See also Path traversal

Parameters

filePathstringrequired

Absolute path to document where you want to save a new embedded file.

embeddedIdstringrequired

Embedded file name. Must be at least 20 characters — use a GUID-based name so it is unique (error 9 otherwise). The document data must reference it in a field, or the file is deleted automatically.

datastring or byte[]required

Either base64 encoded string or an array of bytes.

Returns

true when the file is saved. Throws an error otherwise, for example when the document is not found, when an embedded file with the same name already exists, when data is not base64 or a byte array, or when the document has no schema (embedded files require a schema-bound document).

Example

Normal JavaScript, running in the browser or on the Docly™ server.
// ... JS setting "email" variable of user to update ...

let uploads = docly.getUploads();
if (uploads.length != 1) throw new Error("Expected 1 upload");

let upload = uploads[0];
let filedata = docly.getUploadBase64(upload.Name);
let type = upload.ContentType.toLowerCase();

if (type != "image/jpeg" && type != "image/png" && type != "image/gif")
    throw new Error("Only JPEG, PNG or GIF image files are supported as profile picture.");

let extension = type.split("/")[1];
let filename = docly.guid() + "." + extension;

let save = docly.saveEmbeddedFile("Member users/" + email, filename, filedata);
if (save) {
    // Reference the embedded file in the 'Image' field
    docly.patchFile("Member users/" + email, { Image: filename });
} else {
    throw new Error("Profile picture upload failed");
}