This W3C Editor's Draft specification provides an API for representing file objects in web applications, as well as programmatically selecting them and accessing their data. This includes:
<input type="file">, i.e. when the input element
is in the File Upload state.Blob
object.Additionally, this specification defines objects to be used within threaded web applications for the synchronous reading of files. The interfaces and API can be used with other interfaces and APIs exposed to the web platform.
Opera Presto provides partial support for the W3C File API as described in the following data tables.
For your guide, the following items are supported:
Blob interfaceBlob.slice()File interfaceFileErrorFileException (WebWorkers)FileReaderFileReaderSync (WebWorkers)files property in the HTMLInputElement
HTMLInputElement interface has a readonly attribute of type FileList.The following items are not supported:
window.createObjectURL()window.revokeObjectURL()blob: urlsFileReader[Sync].readAsArrayBuffer (this is waiting for the WebGL support)This interface represents raw data. It provides a method to slice data objects between ranges of bytes into further chunks of raw data. It also provides an attribute representing the size of the chunk of data.
| Attribute | Description | Support |
|---|---|---|
size
|
Represents the size of the Blob object in bytes. | Yes |
type
|
Represents the ASCII-encoded string in lower case representing the media type of the Blob. | Yes |
| Method | Parameter | Description | Support |
|---|---|---|---|
slice
|
Returns a new Blob object between the ranges of bytes specified. | Yes | |
start
|
This is a value for the start point of a slice call.
|
Yes | |
length
|
This is a value for the end point of a slice call as byte offsets from start.
|
Yes | |
contentType
|
This is optional, and can be used to set a value identical to one that is set with the HTTP/1.1 Content-Type header on the Blob returned by the slice call. | Yes |
This interface describes a single file in a FileList and exposes its name. It inherits from Blob.
It is available on objects that expose an attribute of type FileList; these objects are defined in HTML5.
| Attribute | Description | Support |
|---|---|---|
name
|
The name of the file.
|
Yes |
lastModifiedDate
|
The last modified date of the file.
|
Yes |
This interface provides methods to read Files or Blobs into memory, and to access the data from those Files or Blobs using
progress events and event handler attributes. It is desirable to read data from file systems asynchronously
in the main thread of user agents. This interface provides such an asynchronous API, and is specified to be used with the
global object (Window).
| Constructor | Description | Support |
|---|---|---|
FileReader()
|
When the FileReader() constructor is invoked, the user agent MUST return a new FileReader object.
|
Yes |
The following data table describes the event handler attributes (and their corresponding event handler event types) that
user agents MUST support on FileReader as DOM attributes.
| Attribute | Event type | Description | Support |
|---|---|---|---|
onloadstart
|
loadstart
|
Dispatched when the read starts. | Yes |
onprogress
|
progress
|
Dispatched while reading (and decoding) blob, and reporting partial Blob data (progess.loaded/progress.total).
|
Yes |
onabort
|
abort
|
Dispatched when the read has been aborted. For instance, by invoking the abort() method.
|
Yes |
onerror
|
error
|
Dispatched when the read has failed. | Yes |
onload
|
load
|
Dispatched when the read has successfully completed. | Yes |
onloadend
|
loadend
|
Dispatched when the request has completed (either in success or failure). | Yes |
The FileReader object can be in one of three states. The readyState attribute, on getting, MUST
return the current state, which MUST be one of the following values:
| State | Numeric value | Description | Support |
|---|---|---|---|
EMPTY
|
0
|
The object has been constructed, and there are no pending reads. | Yes |
LOADING
|
1
|
A File or Blob is being read.
|
Yes |
DONE
|
2
|
The entire File or Blob has been read into memory, or a file error occurred during read, or the read was aborted using
abort().
|
Yes |
The FileReader interface makes available four asynchronous read methods which read files into memory. If multiple read methods
are called on the same FileReader object, user agents MUST only process the last call to a read
method, which is the call that occurs last in a script block that has the "already started" flag set.
| Read Method | Description | Support |
|---|---|---|
readAsArrayBuffer()
|
When the readAsArrayBuffer(blob) method is called, the user agent MUST run the steps below (unless otherwise
indicated).
|
No |
readAsBinaryString()
|
When the readAsBinaryString(blob) method is called, the user agent MUST run the following steps (unless otherwise
indicated):
|
Yes |
readAsText()
|
When the readAsText(blob, encoding) method is called (the encoding argument is optional), the
user agent MUST run the following steps (unless otherwise indicated):
|
Yes |
readAsDataURL()
|
When the readAsDataURL(blob) method is called, the user agent MUST run the following steps (unless otherwise
indicated):
|
Yes |
On getting, the result attribute returns a Blob's data as a DOMString, or as an ArrayBuffer,
or null, depending on the read method that has been called on the FileReader, and
any errors that may have occurred. It can also return partial Blob data.
| Attribute | Description | Support |
|---|---|---|
result
|
|
Yes |
| Method | Description | Support |
|---|---|---|
abort
|
When the abort() method is called, the user agent MUST run the following steps:
|
Yes |
Many methods in this specification take mandatory Blob parameters. The Blob argument is used to call all four
asynchronous read methods on FileReader and all four synchronous read methods on
FileReaderSync; it is also used to call the createObjectURL method. For the purposes of this specification,
it will typically be a reference to a single File in a FileList or a Blob object not obtained
from the file system that is in scope of the global object from which the method call was made.
Blob URIs are created and revoked using methods exposed on the URL object, supported by global objects Window
(in HTML5) and WorkerGlobalScope (in Web Workers). Opera Presto does not yet support this.
| Method | Description | Support |
|---|---|---|
createObjectURL()
|
Returns a unique Blob URI each time it is called on a valid blob argument, which is a non-null Blob in scope of the global object's URL property from which this static method is called. | No |
revokeObjectURL()
|
Revokes the Blob URI provided in the string url argument.
|
No |
| Event name | Interface | Description | Support |
|---|---|---|---|
loadstart
|
ProgressEvent
|
Dispatched when the read starts. | Yes |
progress
|
ProgressEvent
|
Dispatched while reading (and decoding) blob, and reporting partial Blob data (progess.loaded/progress.total)
|
Yes |
abort
|
ProgressEvent
|
Dispatched when the read has been aborted. For instance, by invoking the abort() method.
|
Yes |
error
|
ProgressEvent
|
Dispatched when the read has failed (see errors). | Yes |
load
|
ProgressEvent
|
Dispatched when the read has successfully completed. | Yes |
loadend
|
ProgressEvent
|
Dispatched when the request has completed (either in success or failure). | Yes |
This interface provides methods to read files or Blobs into memory, and to access the data of these files or Blobs.
| Constructor | Description | Support |
|---|---|---|
FileReaderSync()
|
When the FileReaderSync() constructor is invoked, the user agent MUST return a new FileReaderSync
object. In environments where the global object is represented by a WorkerGlobalScope object, the FileReaderSync
constructor MUST be available.
|
Yes |
| Method | Description | Support |
|---|---|---|
readAsBinaryString()
|
When the readAsBinaryString(blob) method is called, the following steps MUST be followed:
|
Yes |
readAsText()
|
When the readAsText(blob, encoding) method is called (the encoding argument is optional), the following steps
MUST be followed:
|
Yes |
readAsDataURL()
|
When the readAsDataURL(blob) method is called, the following steps MUST be followed:
|
Yes |
readAsArrayBuffer()
|
When the readAsArrayBuffer(blob) method is called, the following steps MUST be followed:
|
No |
This interface is used to report errors asynchronously. The FileReader object's error attribute
is a FileError object, and is accessed asynchronously through the onerror event handler when error
events are generated. Conforming user agents that make available the FileReader() constructor on their global
objects MUST also make available the FileError interface object.
The code attribute MUST return one of the constants of the FileError error, which MUST be the
most appropriate code from the following "Error code descriptions" table.
Errors in the synchronous read methods for Web Workers are reported using the FileException exception.
Conforming user agents that make available the FileReaderSync() constructor on WorkerGlobalScope
MUST also make available the FileException interface object.
The code attribute MUST return one of the constants of the FileException exception, which MUST
be the most appropriate code from the following "Error code descriptions" table.
| Constant | Code | Situation | Support |
|---|---|---|---|
NOT_FOUND_ERR
|
1
|
User agents MUST use this code if the File or Blob resource could not be found at the time the read was processed. | Yes |
SECURITY_ERR
|
2
|
This is a security error code to be used in situations not covered by any other error codes. User agents MAY use this code
if:
|
Yes |
ABORT_ERR
|
3
|
User agents MUST use this code if the read operation was aborted, typically with a call to abort().
|
Yes |
NOT_READABLE_ERR
|
4
|
User agents MUST use this code if the File or Blob cannot be read, typically due due to permission problems that occur after a reference to a File or Blob has been acquired (e.g. concurrent lock with another application). | Yes |
ENCODING_ERR
|
5
|
User agents MAY use this code if URL length limitations for Data URLs in their implementations place limits on the File
or Blob data that can be represented as a Data URL. User agents MUST NOT use this code for the asynchronous readAsText()
call and MUST NOT use this code for the synchronous readAsText() call, since encoding is determined by the
encoding determination algorithm.
|
Yes |
Need help? Hit F1 anytime while using Opera to access our online help files, or go here.