Save and serialize designs in CE.SDK for later retrieval, sharing, or storage using string or archive formats.
CE.SDK provides two formats for persisting designs. Choose the format based on your storage and portability requirements.
Save Format Comparison#
| Format | Method | Assets | Best For |
|---|---|---|---|
| String | saveToString() |
Referenced by URL | Database storage, cloud sync |
| Archive | saveToArchive() |
Embedded in ZIP | Offline use, file sharing |
String format produces a lightweight serialized string where assets remain as URL references. Use this when asset URLs will remain accessible.
Archive format creates a self-contained ZIP with all assets embedded. Use this for portable designs that work offline.
Persist saved files of either format with the .imgly extension. The .scene and .zip extensions also load, and the same engine.scene.load(from:) call opens either kind.
Save to String#
Serialize the current scene to a string suitable for database storage.
let sceneString = try await engine.scene.saveToString()The string contains the complete scene structure but references assets by their original URLs.
Save to Archive#
Create a self-contained ZIP with the scene and all embedded assets.
let archiveBlob = try await engine.scene.saveToArchive()saveToArchive() returns a Blob (a Data value) that includes all pages, elements, and asset data in a single portable file.
Compression Options#
CE.SDK supports optional compression for saved scenes to reduce file size. Compression is particularly useful for large scenes or when storage space is limited.
let compressed = try await engine.scene.saveToString( options: SaveToStringOptions( compression: CompressionOptions(format: .zstd, level: .default), ),)Compression Formats:
CompressionFormat.none— No compression (default)CompressionFormat.zstd— Zstandard compression (recommended for best performance)
Compression Levels:
CompressionLevel.fastest— Fastest compression, larger outputCompressionLevel.default— Balanced speed and size (recommended)CompressionLevel.best— Best compression, slower
Compression adds minimal overhead while reducing scene size by approximately 64%. The default level provides the best balance of speed and compression ratio.
Write to Disk#
Use Foundation’s file APIs to persist saved designs to the file system.
Scene strings can be written directly as text:
let sceneURL = outputDir.appendingPathComponent("scene.imgly")try sceneString.write(to: sceneURL, atomically: true, encoding: .utf8)Archives are returned as Data, which writes to disk in a single call:
let archiveURL = outputDir.appendingPathComponent("archive.imgly")try archiveBlob.write(to: archiveURL)Load Scene from File#
Read a previously saved .scene file from disk and restore it to the engine with engine.scene.load(from:).
let restoredString = try String(contentsOf: sceneURL, encoding: .utf8)try await engine.scene.load(from: restoredString)Scene files are lightweight but require the original asset URLs to remain accessible.
Load Archive from File#
Use engine.scene.load(from:) with a local file URL to restore a self-contained archive that includes all embedded assets — the same call that loads scene files, since the engine detects the file kind automatically.
try await engine.scene.load(from: archiveURL)Archives are portable and work offline since all assets are bundled within the file.
API Reference#
| Method | Description |
|---|---|
engine.scene.saveToString() |
Serialize scene to string with optional compression |
engine.scene.saveToArchive() |
Save scene with assets as ZIP Data |
engine.scene.load(from:) |
Load a scene or archive from a string or URL (file kind detected automatically) |
engine.scene.loadArchive(from:) |
Load a scene archive from a URL |
engine.block.saveToString() |
Serialize specific blocks to a string |
engine.block.saveToArchive(blocks:) |
Save specific blocks with assets as ZIP Data |
engine.block.load(from:) |
Load blocks from a serialized string or URL |
engine.block.loadArchive(from:) |
Load blocks from a ZIP archive URL |
Next Steps#
- Export Overview — Export designs to image, PDF, and video formats
- Load Scene — Load scenes from remote URLs and archives
- Store Custom Metadata — Attach metadata like tags or version info to designs
- Partial Export — Export individual blocks or selections