1. Goals
This specification documents the types and operations made available by web browsers to script when a hierarchy of files and directories are dragged and dropped onto a page or selected using form elements, or equivalent user actions.
This is heavily based upon earlier drafts of [file-system-api] which defines similar types in the context of a sandboxed file system, including operations for creating and modifying files and directories, but which has not been broadly adopted by web browsers.
note: The APIs described by this document was initially implemented in Google Chrome. Other browsers (at this time: Edge, Firefox and Safari) are starting to support subsets of Chrome’s APIs and behavior. The intent of this document is to specify the common subset to ensure that the implementations are interoperable.
2. Concepts
2.1. Names and Paths
A name is a string which:
-
does not contain '/' (U+002F SOLIDUS)
-
does not contain NUL (U+0000)
-
does not contain '\' (U+005C REVERSE SOLIDUS)
-
is not '.' (U+002E FULL STOP)
-
is not '..' (U+002E FULL STOP, U+002E FULL STOP)
A path segment is a name, '.' (U+002E FULL STOP) or '..' (U+002E FULL STOP, U+002E FULL STOP).
A relative path is a string consisting of one or more path segments joined by '/' (U+002F SOLIDUS) that does not start with '/' (U+002F SOLIDUS).
An absolute path is a string consisting of '/' (U+002F SOLIDUS) followed by zero or more path segments joined by '/' (U+002F SOLIDUS).
A path is either a relative path or an absolute path.
A valid path is a USVString which is a path.
2.2. Files and Directories
A file consists of binary data and a name (a non-empty name).
A directory consists of a name (a name) and an ordered list of members. Each member is either a file or a directory. Each member of a directory must have a distinct non-empty name.
A root directory is a directory that is not a member of a directory. A root directory’s name is empty.
The parent of a file or directory is the directory it is a member of. A root directory has no parent.
note: In most cases, the files and directories selected by the user will be presented by the API as if contained by a virtual root that does not exist as an entity in the actual native file system backing the interaction with the API.
A file system consists of a name and a root which is an associated root directory. The name of a file system is a USVString which is implementation defined but is unique to the file system. A root directory is associated with exactly one file system.
note: Implementations could produce a name by generating a UUID for each file system instance with some fixed prefix and suffix strings applied. Authors using the API are adviised not to make assumptions about the structure or content of the names.
2.3. Entries
An entry is either a file entry or a directory entry.
An entry has an name (a name) and a full path (an absolute path).
An entry also has a root, which is an associated root directory.
note: Entries are defined in terms of paths relative to a root directory to account for the fact that a native file system backing the interaction with the API could be modified asynchronously during operations such as enumerating the contents of a directory. Operations exposed on entries will produce errors in such cases where the paths no longer reference the same entity.
The file system of an entry is the file system associated with the entry’s root.
3. Algorithms
To resolve a relative path with abspath (an absolute path) and path (an absolute path, a relative path, or the empty string), perform the following steps. They return an absolute path.
-
If path is an absolute path, return path.
-
Let abspath segments be the result of strictly splitting abspath on '/' (U+002F SOLIDUS).
note: The first string will be empty.
-
Let path segments be the result of strictly splitting path on '/' (U+002F SOLIDUS).
-
For each segment in path segments, switch on segment:
- empty string
-
Continue.
- '.' (U+002E FULL STOP)
-
Continue.
- '..' (U+002E FULL STOP, U+002E FULL STOP)
-
Remove the last member of abspath segments unless it is the only member.
- Otherwise
-
Append