freecoding.school100% FREE · NO SIGNUP
API ArcadeISSUE #10 of 23

file api · File · Blob · FileReader

ApiaVSLegacy Larry
Apia saysThe File API reads user-selected or dropped files via File, Blob, and FileReader.

A file input or drop gives you File objects (a kind of Blob) with name, size, type. Read them with FileReader (readAsText, readAsDataURL) or the modern promise-based file.text()/file.arrayBuffer(). URL.createObjectURL(file) makes a preview URL — revoke it when done.

Power-ups you unlock

Legacy Larry attacks — common mistakes

Boss battleRead a chosen text file and display its contents with file.text().

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><input type="file" id="f"><pre id="o"></pre>
<script>document.getElementById('f').onchange=async e=>{const file=e.target.files[0];if(file)document.getElementById('o').textContent=(await file.text()).slice(0,200);};</script></body></html>
▶ Open the interactive comic issue
‹ Drag And Drop Api · Dragstart · DropService Workers · Install · Activate · Fetch ›