This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

FileList

Summary

FileList is an object which represents an array of individually selected files from the underlying system.

Properties

length
length returns the number of files in the FileList object. If there are no files, this attribute must return 0.

Methods

item
item returns the indexth File object in the FileList. If there is no indexth File object in the FileList, then this method must return null.

Events

No events.

Examples

iterates over all the files selected by the user using an input element

// fileInput is an HTML input element: input type="file" id="myfileinput" multiple
var fileInput = document.getElementById("myfileinput");

// files is a FileList object (similar to NodeList)
var files = fileInput.files;
var file;

// loop trough files
for (var i = 0; i < files.length; i++) {

    // get item
    file = files.item(i);
    //or
    file = files[i];

    alert(file.name);
}

Related specifications

W3C File API Specification
W3C Working Draft

Attributions