Interactive API reference for the JavaScript File Object. File is a Blob that represents a file from the filesystem. You can get Files from the   ‎FileReader · ‎Blob · ‎FileList. The File API provides us access to file information via JavaScript and an input[type=file] element. Let's have a look at how the File API works! The HTML5 File API allows you to create applications that let the user interact with files locally. Basically Accessing A File Using JavaScript.


Author: Etha Robel III
Country: Bulgaria
Language: English
Genre: Education
Published: 22 February 2016
Pages: 775
PDF File Size: 49.33 Mb
ePub File Size: 6.98 Mb
ISBN: 408-9-61926-293-9
Downloads: 91137
Price: Free
Uploader: Etha Robel III


A FileList interface, which represents an array of individually selected files from the underlying system.


A Blob interface, which represents immutable raw binary data, and javascript file api access to ranges of bytes within the Blob object as a separate Blob. A File interface, which includes readonly informational attributes about a file such as its name and the date of the last modification on disk of the file.

A FileReader interface, which provides methods to read a File or a Bloband an event model to obtain javascript file api results of these reads.

The FileList object represents a list of files in the local file system. For instance, a list of files inside a directory. You will see how these file API objects are used in the following sections. Here is an input element example: You need an onchange listener too.

Here is how that looks: When that button is clicked the user is shown a file dialog. In that file dialog the user can choose a javascript file api. The chosen file will be made available to the onchange listener via the event object passed as parameter to it.

Selecting Multiple Files To enable the user to select multiple files, insert the multiple attribute into the input element. Here is a code example showing how to setup a drop zone HTML element so that you can detect when files are dragged onto it: When a file is dropped onto the drop zone HTML element, the drop function will be called.

The list of files dragged onto javascript file api drop zone element can be found in the event.

Table of Contents

The dragOver function is not strictly javascript file api. It just shows that the file being dragged is copied. This is shown via the javascript file api file icon. The rest of the code needed to access the selected files is the same as when selecting a file via the input element.

You will see how that looks in the following sections. It might be a good idea to style the drop zone HTML element to make it clear to the user that they can drag a file onto it, and where the borders of the drop zone are etc.

File - an individual file; provides readonly information such as name, file size, mimetype, and a reference to the file handle.

  • File JavaScript API
  • Reading local files in JavaScript - HTML5 Rocks
  • HTML5 File API
  • FileAPI API

FileList - an array-like sequence of File objects. Blob - Allows for slicing a file into byte ranges. When used in conjunction with the above data structures, the FileReader interface can be used to asynchronously read a file through familiar Javascript file api event handling.

FileAPI — a set of javascript tools for working with files.

Javascript file api, it is possible to monitor the progress of a read, catch errors, and determine when a load is complete. All the File APIs are supported. JavaScript returns the list of selected File objects as a Javascript file api.

Here's an example that uses the 'multiple' attribute to allow selecting several files at once: