A ready Node.js script, with no packages, that uploads your build and waits for its stream test. Prefer a package? E3DS CI/CD for Node.js on npm does the same in two lines. Part of Automated upload.
E3DS_API_KEY - never written into the script._. Uploading again under the same name adds a new version.Node.js 18 or newer, no packages. Save as e3ds-upload.mjs, then:
export E3DS_API_KEY="your API key"
node e3ds-upload.mjs MyGame.zip MyGame
#!/usr/bin/env node
// Upload an Unreal / Unity build (.zip) to Eagle 3D Streaming and wait for its stream test.
//
// node e3ds-upload.mjs <build.zip> <app name> [--part-size MB] [--parallel N] [--timeout MIN] [--no-wait] (Node.js 18 or newer, nothing to install)
//
// --part-size MB size of each part (default: our server picks; 5 MB .. 5 GB, at most 10,000 parts).
// A part size as big as the file = a one-part upload.
// --parallel N how many parts are sent at the same time (default 4).
//
// Your API key is read from the environment variable E3DS_API_KEY (Control Panel -> Developer Section -> API key).
// --timeout MIN how long to wait for the stream-test result (default 45).
// --no-wait upload only; the result comes by email and in the Control Panel.
// If the upload stops (network, closed window), run the same command again: it continues where it stopped.
// Exit codes (the same in the Python and PowerShell scripts):
// 0 passed (also "passed, but a newer version is live") or uploaded with --no-wait; 1 the stream test failed;
// 2 not tested - a newer upload of the same app is tested instead; 3 no result within --timeout;
// 4 the upload itself failed (API key, file, network) - run the same command again to continue it.
// Same steps as the REST guide:
// 1. POST /v1/uploads/app-builds 2. PUT each part 3. POST /v1/uploads/app-builds/<uploadId>/complete
// 4. (optional) GET /v1/uploads/app-builds/<uploadId>
import { open, stat } from "node:fs/promises";
import { basename } from "node:path";
const API = (process.env.E3DS_API_BASE || "https://agw.eagle3dstreaming.com").replace(/\/$/, "");
let WAIT_MINUTES = Number(process.env.E3DS_WAIT_MINUTES ?? 45); // --timeout MIN / --no-wait override it
const TRIES = 6, METHOD = "nodejs";
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const js = (text) => { try { return JSON.parse(text || "{}"); } catch (e) { console.log(` (answer is not JSON: ${e.message})`); return {}; } };
const errorText = (r) => { const e = js(r.text).error; return `HTTP ${r.status}: ${e?.message ?? e ?? r.text.slice(0, 300)}`; };
const fail = (msg) => { throw new Error(msg); };
// One HTTP request with retries on network errors and 5xx.
async function call(method, url, { body, headers = {}, data } = {}) {
const h = { ...headers };
if (body !== undefined) { data = JSON.stringify(body); h["Content-Type"] = "application/json"; }
let last;
for (let attempt = 1; attempt <= TRIES; attempt++) {
try {
const r = await fetch(url, { method, headers: h, body: data });
if (r.status < 500) return { status: r.status, headers: r.headers, text: await r.text() };
last = `HTTP ${r.status}`;
} catch (e) { last = e.cause ? `${e.message}: ${e.cause.code || e.cause.message}` : e.message; } // fetch puts the real reason in e.cause
console.log(` try ${attempt}/${TRIES} failed (${last})${attempt < TRIES ? " - trying again" : ""}`);
if (attempt < TRIES) await sleep(Math.min(30000, 2 ** attempt * 1000)); // no wait after the last try
}
fail(`Giving up after ${TRIES} tries: ${last}`);
}
async function readPart(fh, n, partSize, size) {
const buf = Buffer.alloc(Math.min(partSize, size - (n - 1) * partSize));
await fh.read(buf, 0, buf.length, (n - 1) * partSize);
return buf;
}
// start -> parts -> complete -> (wait). Our server starts the stream test by itself after complete.
async function upload(file, app, key, size, fh, { partMB, parallel }) {
const auth = { Authorization: `Bearer ${key}` };
const base = `${API}/v1/uploads/app-builds`;
const start = { app, fileName: basename(file), fileSize: size, method: METHOD };
if (partMB) start.partSize = Math.round(partMB * 1048576);
let r = await call("POST", base, { body: start, headers: auth });
if (r.status >= 300) fail(`Could not start the upload (${errorText(r)})`);
const up = js(r.text);
const { uploadId, version } = up, partSize = Number(up.partSize), total = Number(up.totalParts);
const done = new Set((up.doneParts || []).map((p) => Number(p.partNumber ?? p)));
const urls = new Map((up.parts || []).map((p) => [p.partNumber, p.url]));
const todo = []; for (let n = 1; n <= total; n++) if (!done.has(n)) todo.push(n);
console.log(`1. upload started: app '${app}', version ${version}, ${total} part(s) of ${+(partSize / 1048576).toFixed(2)} MB, ${parallel} at a time${done.size ? ` - resuming, ${done.size} part(s) already sent` : ""}`);
let sent = Math.min(size, done.size * partSize);
for (let i = 0; i < todo.length; i += parallel) {
const batch = todo.slice(i, i + parallel);
const missing = batch.filter((n) => !urls.has(n));
if (missing.length) { // more part addresses
r = await call("POST", `${base}/${uploadId}/parts`, { body: { partNumbers: missing }, headers: auth });
if (r.status >= 300) fail(`Could not get part addresses (${errorText(r)})`);
for (const p of js(r.text).parts) urls.set(p.partNumber, p.url);
}
await Promise.all(batch.map(async (n) => {
const p = await call("PUT", urls.get(n), { data: await readPart(fh, n, partSize, size), headers: { "Content-Type": "application/octet-stream" } });
if (p.status >= 300) fail(`Part ${n} was not accepted (HTTP ${p.status}).`);
}));
sent = Math.min(size, sent + batch.length * partSize);
console.log(`2. sent ${(sent / 1048576).toFixed(1)} / ${(size / 1048576).toFixed(1)} MB (${Math.floor((100 * sent) / size)}%)`);
}
r = await call("POST", `${base}/${uploadId}/complete`, { headers: auth });
if (r.status >= 300) fail(`Could not complete the upload (${errorText(r)})`);
console.log(`3. upload complete (${js(r.text).state || "queued"}) - our server starts the stream test by itself`);
if (!(WAIT_MINUTES > 0)) { console.log(" not waiting: the result comes by email and in the Control Panel"); return 0; }
const deadline = Date.now() + WAIT_MINUTES * 60000;
while (Date.now() < deadline) {
await sleep(30000);
r = await call("GET", `${base}/${uploadId}`, { headers: auth });
const s = js(r.text);
if (s.state === "passed") { console.log(`4. PASSED - app '${app}', version ${version} ${s.live !== false ? "is live" : `passed, but a newer version is live (${s.liveVersion})`}`); return 0; }
if (s.state === "failed") { console.log(`4. FAILED: ${s.reason} ${s.report || ""}`); return 1; }
if (s.state === "replaced") { console.log(`4. REPLACED by a newer upload ${s.replacedBy || ""} - version ${version} was not tested (live version: ${s.liveVersion})`); return 2; }
console.log(` ${new Date().toLocaleTimeString()} ${s.state || `HTTP ${r.status}`}...`);
}
console.log(`4. NO RESULT after ${WAIT_MINUTES} minutes - it will come by email and in the Control Panel`);
return 3;
}
async function main() {
const args = [], opts = { partMB: 0, parallel: 4 };
const argv = process.argv.slice(2);
while (argv.length) {
const a = argv.shift();
if (a === "--part-size" && argv.length) opts.partMB = Number(argv.shift());
else if (a === "--parallel" && argv.length) opts.parallel = Math.max(1, parseInt(argv.shift(), 10) || 4);
else if (a === "--timeout" && argv.length) WAIT_MINUTES = Number(argv.shift());
else if (a === "--no-wait") WAIT_MINUTES = 0;
else args.push(a);
}
const [file, app] = args;
if (args.length !== 2) { console.log("usage: node e3ds-upload.mjs <build.zip> <app name> [--part-size MB] [--parallel N] [--timeout MIN] [--no-wait]"); return 4; }
const key = process.env.E3DS_API_KEY;
if (!key) { console.log("Set E3DS_API_KEY to your API key first."); return 4; }
const size = (await stat(file)).size;
console.log(`Uploading ${basename(file)} (${(size / 1048576).toFixed(1)} MB) as app '${app}' to ${API}`);
const fh = await open(file, "r");
try {
return await upload(file, app, key, size, fh, opts);
} finally { await fh.close(); }
}
main().then((code) => process.exit(code)).catch((e) => { console.log("UPLOAD FAILED:", e.message); process.exit(4); });
Nothing extra is needed to resume. If the upload stops - the network drops, the computer sleeps, the window is closed, Ctrl+C - just run the same command again, with the same zip and the same app name, within 24 hours:
node e3ds-upload.mjs MyGame.zip MyGame
The script finds the unfinished upload by itself and sends only the parts that are still missing. Its first line then
says resuming, N part(s) already sent, and the version number stays the same. A part that fails on its
own is sent again automatically (up to six tries), so a short network hiccup needs nothing from you at all.
Video of a real run: youtu.be/c0x8wsBRiCs. How it works: Resumable uploads.
Every message the script can print, and what it means: when it fails. How to store the key in a pipeline: keep your API key safe. The other ways to upload automatically: Automated upload.
Last updated