File API is the W3C specification that lets a web page work with files the user picks, using the interfaces Blob, File, FileList and FileReader. A page reads a file in the browser without sending it to a server. It is the layer between an input element of type file and everything that handles bytes in JavaScript. The spec is an Editor's Draft maintained by the W3C Web Applications Working Group.
The spec defines four main pieces:
Users get File objects from input type=file (the files property), from drag and drop (dataTransfer.files) or from other APIs. You can also construct one in code with new File(parts, name, { type, lastModified }). If you omit lastModified, it defaults to the current time, equal to Date.now(). The constructor requires both the parts array and the name.
A File is immutable and represents the data at the moment a read begins. If the file no longer exists on disk when you read it, the read fails with an error, and the spec names NotFoundError for the synchronous reader in workers.
const f = new File(['abc'], 'a.txt', { type: 'text/plain', lastModified: 1767225600000 });
console.log(f.name, f.size, f.type, f.lastModified, new Date(f.lastModified).toISOString());
console.log(f instanceof Blob, Object.prototype.toString.call(f));
const g = f.slice(1); console.log(g instanceof File, g instanceof Blob, g.name);
try { new File(['x']); } catch (e) { console.log(e.name + ': ' + e.message); }
Output from Node 22.22.0:
a.txt 3 text/plain 1767225600000 2026-01-01T00:00:00.000Z
true [object File]
false true undefined
TypeError: The "fileBits" and "fileName" arguments must be specified
A File is a Blob that also has a name and a lastModified time. Use Blob for anonymous data you generate, and File for something that should keep a file name, such as an upload. The slice() method on a File returns a plain Blob, so the name is lost, as the output above shows.
No. It only reads and represents them locally. To upload, put a File in FormData and send it with fetch, or pass it as the request body directly. The browser then sends the bytes and a multipart Content-Disposition filename.