Skip to content
>_ TrueFileSize.com
TrueFileSize Editorial··8 min read

Generate Sample Files in the Browser (No Upload Needed)

I used to keep a folder called throwaway-test-files on my desktop. It had twelve versions of test.csv, three mystery JSON files, and one final-final-upload-test.txt that was absolutely not final.

That folder exists because testing file inputs is annoying. You need a specific extension, maybe a specific size, and you do not want to upload private files just to see whether a form accepts them. A browser-based sample file generator fixes that: it creates the file locally, lets you choose a custom file size, and downloads it without sending the bytes to a server.

The short version

The browser already has the pieces:

  • TextEncoder turns text into bytes.
  • Uint8Array creates raw binary buffers.
  • Blob wraps 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.

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

When I test a new upload flow, I usually do this:

  1. Generate a 1KB TXT file to verify the happy path.
  2. Generate a 100KB CSV to check import preview.
  3. Generate a 1MB JSON file to test parser performance.
  4. Generate a 10MB BIN file to check progress and limit messaging.
  5. Use a CDN-hosted file from Download Tests if I need anything bigger.

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 10MB, and download the file. The generated bytes stay in your browser.