Skip to main content

Upload and Download Files

Transfer files between your local machine and cloud browser sessions. Handle document uploads, file exports, and downloads without external storage services.

Why You Need This

Your agent is filling out a government form that requires a document upload. The form is running in a cloud browser, but the document is on your local machine. Or your agent triggers a CSV download inside the cloud browser - a report, an export, a receipt - and you need that file locally.

The File Service bridges the gap. It transfers files between your local machine and a remote cloud browser on TestMu AI Browser Cloud - without needing external storage services like S3 or GCS. Files are sent directly through the browser's page context using Base64 encoding.

Upload a File to the Cloud Browser

const fileBuffer = fs.readFileSync('document.pdf');
await client.files.uploadToSession(session.id, fileBuffer, 'document.pdf');

How it works: The buffer is Base64-encoded, sent to the cloud browser via page.evaluate(), decoded in the browser, and set on the file input element.

Download a File from the Cloud Browser

By URL:

const result = await client.files.downloadFromSession(
session.id,
'https://example.com/report.csv'
);
fs.writeFileSync('report.csv', result);

How it works: The cloud browser fetches the URL, reads the response with FileReader, converts to Base64, and returns the data back to Node.js.

For files triggered by button clicks (not direct URLs), the service uses CDP's Fetch.enable to intercept the download.

Session-Scoped File API

All file operations are also available under client.sessions.files:

await client.sessions.files.upload(session.id, buffer, 'file.txt');

const files = await client.sessions.files.list(session.id);

const data = await client.sessions.files.download(session.id, '/path/to/file');

const archive = await client.sessions.files.downloadArchive(session.id);

await client.sessions.files.delete(session.id, '/path/to/file');

await client.sessions.files.deleteAll(session.id);

File Info

interface FileInfo {
path: string;
name: string;
size: number;
createdAt: string;
mimeType?: string;
}

Files are stored locally in a .files/ directory organized by session ID.

Test across 3000+ combinations of browsers, real devices & OS.

Book Demo

Help and Support

Related Articles