Docly Developers
Function API only Updated 17 Oct 2026

extractBase64Images(html)

Extracts base64-encoded images from an HTML string and replaces each one with a Content ID (cid:) reference, the way images are referenced in email attachments. Nothing is saved — the function returns the images so you can store them yourself, for example with saveEmbeddedFile, or use extractAndEmbedBase64Images to extract and save in one step.

Only src attributes in double quotes are recognised (src="data:image/png;base64,..."), and only the types png, jpg, jpeg, gif, webp, avif, heic and heif. SVG is not extracted.

Parameters

htmlstringrequired

The HTML string that contains images encoded in base64 format, which are to be extracted.

Returns

An object { Html, Images }. Html is the HTML with each image replaced by src="cid:<ContentId>". Images is a list of { Base64, Type, ContentId, Mime }.

Example

Normal JavaScript, running in the browser or on the Docly™ server.
let html = '<html><body><h1>Sample Image</h1><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="small image"/></body></html>';
let extract = docly.extractBase64Images(html);
return extract;   // { Html, Images: [ { Base64, Type, ContentId, Mime } ] }