Backend-created sessions
Keep source URLs and server authorization off the client while the SDK handles polling and downloads.
Use a backend-created session when the browser should not receive the full URL list or the credential used to authorize Cloud session creation. Your server creates the session; the browser SDK only receives a session handle and takes over polling and downloads.
When should the backend create the session?
Create the session on your backend in any of these cases:
- The export contains private source URLs, such as R2 presigned URLs, which include your account ID.
- The source list is too large or sensitive to send to the browser.
- Your server must authorize each export.
How is this different from using a public key?
With a public key, the browser sends the file list straight to Eazip. With a backend-created session, your server sends it and the browser never sees it.
| Public key in the browser | Backend-created session | |
|---|---|---|
| Who sends the file list | The browser | Your server |
| Credential | pk_ez_... public key in frontend code | zk_... secret API key on your server |
| Who can start an export | Any visitor on an allowed origin | Whoever your backend authorizes |
| Works on (allowed origins) | Checked against the browser's Origin | Not checked |
| Files from, modes, and limits | Enforced | Enforced the same way |
| SDK option | publicKey + files | createSession |
Both flows use the same public key settings in the dashboard. A backend-created session still needs a public key: its Files from hosts, allowed modes, and limits decide what the session may fetch. The key must have at least one Works on origin even if only your backend creates sessions.
Implement it
Create the session on your backend
Add an endpoint that your frontend can call. It should:
- authorize the signed-in user for this export;
- build the file list on the server, from your own database or storage;
- call
POST /public-apps/{public_key_id}/sessionswith your secret API key; and - return Eazip's response to the browser as is. It contains only the session ID and its client secret, not your source URLs or API key.
You need two values from the dashboard:
EAZIP_API_KEY— a secretzk_...key from API Keys.EAZIP_PUBLIC_KEY_ID— the Key ID (pa_...) of the public key whose settings apply. Under Public keys, open the key's ⋯ menu and choose Copy key ID.
The examples below show only the call to Eazip. Wrap them in your framework's route handler, after your own authorization check.
// POST /api/exports/:exportId/eazip-session
// Authorize the user and load `files` from your database before this call.
async function createEazipSession(files, { zipName, mode }) {
const response = await fetch(
`https://api.eazip.io/public-apps/${process.env.EAZIP_PUBLIC_KEY_ID}/sessions`,
{
method: 'POST',
headers: {
'X-API-Key': process.env.EAZIP_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
files, // [{ url, filename? }, ...]
zip_filename: zipName,
mode, // 'stored' | 'stream'
}),
},
);
const body = await response.json();
if (!response.ok) {
throw new Error(`Eazip session failed: ${body.error.code}`);
}
return body; // { success, session: { id, ... }, client_secret }
}The SDK passes some download options to your callback. Forward the ones you want to honor to the API:
createSession context | Request field |
|---|---|
zipName | zip_filename |
mode | mode |
failOnUrlError | fail_on_url_error |
maxZipSizeBytes | max_zip_size_bytes |
Return only the session
Pass the successful response through, but do not send your secret API key, the private source list, or Eazip's error details back to the browser. Map failures to your own error response.
See the Sessions API for every request field, response field, and error code.
Call your endpoint from the browser
Pass a createSession callback instead of files and publicKey. It
returns { sessionId, clientSecret }, so read those two values from the
response your endpoint passed through:
const job = startZip({
strategy: 'cloud',
zipName: 'export.zip',
filesTotal: 5_000,
createSession: async ({ signal, zipName, mode }) => {
const response = await fetch('/api/exports/123/eazip-session', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
signal,
body: JSON.stringify({ zipName, mode }),
});
if (!response.ok) {
throw new Error('Failed to create Eazip session');
}
const { session, client_secret } = await response.json();
return { sessionId: session.id, clientSecret: client_secret };
},
});filesTotal is optional and only gives the UI an initial count before the first
Cloud poll returns. React is identical — pass the same createSession option to
useEazip().download().
The backend owns source selection and authorization. The browser SDK owns polling, task state, resume, and download actions after it receives the session.
Does resume after a reload work?
Yes. Once your endpoint returns the session, a reload resumes it like any other
Cloud task. Retry is the one difference: the createSession callback cannot be
saved, so after a reload a failed task cannot create a new session. Start a
fresh download() instead. See Sessions and resume
and React persistence.