Skip to main content

Overview

Excalidraw provides flexible data persistence options. You can save drawings to local storage, databases, files, or custom backends. The library includes utilities for serialization, restoration, and file handling.

Local Storage

Using EditorLocalStorage

Excalidraw provides a built-in localStorage wrapper:
From packages/excalidraw/data/EditorLocalStorage.ts:5-53, the EditorLocalStorage class wraps localStorage with error handling and JSON serialization.

Auto-Save Implementation

Automatically save changes to localStorage:

Debounced Auto-Save

Prevent excessive saves with debouncing:

File System

Save to File

Save drawings as .excalidraw files:

Load from File

Load drawings from .excalidraw files:
From packages/excalidraw/data/blob.ts:196-214, loadFromBlob supports loading from .excalidraw, .json, .png (with embedded data), and .svg (with embedded data) files.

Restore Functions

Restore Elements

Safely restore elements from saved data:

Complete Restore Example

Database Storage

Saving to Backend

Save drawings to a backend API:
From packages/excalidraw/data/json.ts:45-68, when using "database" as the type parameter, serializeAsJSON calls clearAppStateForDatabase which strips sensitive/unnecessary data.

Loading from Backend

Load drawings from a backend API:

Image Files with Embedded Data

Save as PNG with Scene Data

Embed scene data in PNG exports:
From packages/utils/src/export.ts:140-157, when exportEmbedScene is true, the scene data is encoded as PNG metadata, allowing the image to be loaded back into Excalidraw.

Binary Files

Managing Image Files

Handle binary image files in drawings:

File ID Generation

Generate unique IDs for files:
From packages/excalidraw/data/blob.ts:259-271, generateIdFromFile creates a SHA-1 hash of the file content for consistent IDs.

Library Storage

Save Library Items

Persist custom library items:

Load Library Items

Restore library items:

Complete Storage Example

Full Persistence Implementation

Next Steps

Export

Learn about exporting to different formats

Embedding

Integrate persistence in embedded apps

Customization

Customize save/load UI

i18n

Localize storage messages