Create a ZIP File in the Browser with JavaScript
Create and download a ZIP from browser files with JavaScript, without uploading files or writing backend ZIP code.
Package browser-selected files into a ZIP with one createZip() call. The
files stay in the browser — no upload and no backend ZIP code.
Before you start
Install the framework-agnostic Core package:
npm install @eazip/coreAdd the file picker
<input id="files" type="file" multiple />
<button id="download" type="button">Download as ZIP</button>Create and download the ZIP
import { createZip } from '@eazip/core';
const fileInput = document.querySelector('#files');
const downloadButton = document.querySelector('#download');
if (!(fileInput instanceof HTMLInputElement)) {
throw new Error('File input not found');
}
if (!(downloadButton instanceof HTMLButtonElement)) {
throw new Error('Download button not found');
}
downloadButton.addEventListener('click', async () => {
if (!fileInput.files?.length) return;
const result = await createZip({
files: fileInput.files,
zipName: 'selected-files.zip',
});
result.download();
});createZip() resolves when the browser-generated ZIP is ready. It accepts a
FileList directly, so no upload or format conversion is required.
Control names and folders
Pass source objects when the path inside the ZIP differs from the browser filename:
const result = await createZip({
files: [
{ file: reportFile, filename: 'reports/annual.pdf' },
{ file: chartBlob, filename: 'reports/chart.png' },
],
zipName: 'reports.zip',
});files accepts these shapes, mixed freely in one array:
| Shape | Example |
|---|---|
| Browser files | File, Blob, FileList |
| URL strings | 'https://cdn.example.com/report.pdf' |
| Named entries | { file, filename } or { url, filename } |
See Inputs and sources for the complete input model.
Know when to use Cloud
Local creation is the shortest path for files already in the browser. Move multi-GB archives or very large URL lists to Eazip Cloud so the job does not depend on one tab.
Continue with Create a ZIP from remote URLs or Create multi-GB ZIP archives with JavaScript.