Learn how to intercept and transform asset URIs in headless Node.js environments for automation and batch processing.
When CE.SDK loads an asset in Node.js, it resolves the URI to an absolute path before fetching. You can intercept this process to add authentication tokens or transform URIs for your automation workflows.
Default URI Resolution#
By default, CE.SDK resolves URIs relative to the basePath setting. Absolute URIs (with http://, https://, data:) pass through unchanged, while relative paths get prepended with basePath.
Use getAbsoluteURI() to test how URIs resolve without loading assets:
// Test resolution without loading assetsconst relativeURI = '/images/photo.jpg';const resolvedURI = await engine.editor.getAbsoluteURI(relativeURI);console.log('Default resolution:');console.log(` Input: ${relativeURI}`);console.log(` Output: ${resolvedURI}`);Custom URI Resolver#
Set a custom resolver to intercept and transform URIs. The resolver receives the URI and a defaultURIResolver function for fallback behavior:
// Set a custom resolver that transforms specific file typesengine.editor.setURIResolver((uri, defaultURIResolver) => { // Transform JPG files to a watermarked version if (uri.endsWith('.jpg')) { console.log(`Custom resolver: Transforming ${uri}`); return 'https://img.ly/static/ubq_samples/sample_1.jpg'; } // Use default resolver for all other URIs return defaultURIResolver(uri);});Important: setURIResolver must be synchronous. Use setURIResolverAsync for async resolution and token fetching.
Adding Authentication#
A common use case is adding authentication tokens to asset URIs. Generate the token before setting the resolver, then append it as a query parameter:
// Pre-generate token BEFORE setting the resolver (must be synchronous)const authToken = 'demo-jwt-token-123';
// Set resolver that adds authentication to specific endpointsengine.editor.setURIResolver((uri, defaultURIResolver) => { // Only add auth token to URIs pointing to your stable link endpoint if (uri.includes('your-server/image-stable-links/')) { const authenticatedURI = `${uri}?auth=${authToken}`; console.log(`\nAuth resolver: Adding token to ${uri}`); console.log(` Result: ${authenticatedURI}`); return authenticatedURI; } // Use default resolver for all other URIs return defaultURIResolver(uri);});
// Test authentication with a protected URIconst protectedURI = 'https://your-server/image-stable-links/abc123';await engine.editor.getAbsoluteURI(protectedURI);Your server validates the token and redirects to the actual asset (e.g., pre-signed S3 URL). CE.SDK follows redirects automatically.
Removing a Resolver#
Restore default behavior by setting a resolver that delegates to defaultURIResolver:
// Remove the custom resolver to restore default behaviorengine.editor.setURIResolver((uri, defaultURIResolver) => defaultURIResolver(uri));console.log('\nโ Removed custom resolver - back to default behavior');Key Constraints#
- Sync vs async:
setURIResolvermust be synchronous; usesetURIResolverAsyncfor async resolution. - Must return absolute URIs: Include scheme (http://, https://, data:)
- One resolver at a time: New calls overwrite previous resolvers
- Delegate unmatched URIs: Pass to
defaultURIResolver()for unchanged paths
Next Steps#
- Configuration โ CE.SDK initialization and baseURL settings
- Load Assets from Remote โ Load assets from remote URLs and servers