Generate Sample Files in the Browser (No Upload Needed)
Keeping ad hoc fixtures such as test.csv and final-upload-test.txt on a developer machine makes bug reports difficult to reproduce. Upload testing often needs a specific extension and byte boundary, without sending private files to a third party. A browser-based sample file generator creates that fixture locally and downloads it without sending the bytes to a server.
The short version
The browser already has the pieces:
TextEncoderturns text into bytes.Uint8Arraycreates raw binary buffers.Blobwraps those bytes as a downloadable file.URL.createObjectURL()gives the Blob a temporary download URL.URL.revokeObjectURL()cleans it up.
No backend. No upload. No R2 write. No database row you have to delete later.
Large generated files still use browser memory before download. A 500MB or 1GB test file is useful, but it can be slow on low-memory devices.
A tiny text file generator
This is the whole idea in plain JavaScript:
function downloadTextFile(filename, text) {
const blob = new Blob([text], { type: "text/plain;charset=utf-8" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = filename;
link.click();
URL.revokeObjectURL(url);
}
downloadTextFile("sample.txt", "hello from the browser\n");
That is enough for TXT, Markdown, LOG, JSON, XML, YAML, TOML, CSV, and HTML if you control the templates. For binary files, skip text entirely:
function makeBinaryFile(sizeInBytes) {
const bytes = new Uint8Array(sizeInBytes);
for (let i = 0; i < bytes.length; i++) {
bytes[i] = i % 256;
}
return new Blob([bytes], { type: "application/octet-stream" });
}
This is why a frontend-only generator can be useful. You are not pretending to make a real PDF or a real MP4. You are generating simple, predictable test files that browsers are good at creating.
Where custom file size matters
Most bugs hide at boundaries:
| Test case | Useful generated file |
|---|---|
| Upload limit says 1MB | Generate 1024KB and 1025KB files |
| Parser accepts JSON only | Generate .json, .txt, and .xml with similar content |
| CSV import times out | Generate CSV files at 100KB, 1MB, and 10MB |
| UI progress bar looks wrong | Generate a BIN file big enough to show progress |
| Validation message is unclear | Generate an unsupported extension and check copy |
The exact byte count is less important than repeatability. If every teammate can create the same custom file size in the browser, your bug report gets easier to reproduce.
What should not be generated in the browser
Some formats look simple but are not:
- PDF needs a real document structure and usually a library.
- DOCX/XLSX/PPTX are zipped Office packages.
- ZIP can hide nested structure, compression behavior, and security edge cases.
- MP4/WebM need actual media containers and encoded streams.
- PNG/JPG/WebP generation usually drags image encoders into the bundle.
That is why TrueFileSize keeps those as prebuilt sample files and large download tests. The browser generator is for lightweight fixtures, not fake complex media.
Use it in real testing
A repeatable upload-flow test can use this sequence:
- Generate a 1KB TXT file to verify the happy path.
- Generate a 100KB CSV to check import preview.
- Generate a 1MB JSON file to test parser performance.
- Generate a 10MB BIN file to check progress and limit messaging.
- Use a CDN-hosted file from Download Tests when the workflow needs bandwidth testing or a 10GB sample.
If you also validate MIME types, pair generated files with the MIME Type Lookup. Browser-generated files are great for workflow testing, but production validation should still check extension, MIME type, and file signatures where possible.
Try it
Open the sample file generator, choose TXT, CSV, JSON, XML, SVG, or BIN, set a custom file size up to 1GB, and download the file. The generated bytes stay in your browser.