Methods
fileChooserItems() → {Array.<Object>}
Override the base class implementation to fit the needs of this class. The parent class requires the file system to be able to list its files, but the offline file system cannot do so, because JavaScript in the browser has no access to the user's hard drive. Therefore, this file system needs a different UI than the one the parent class provides.
Here, we provide two ways for a user to upload a file from their own files. This function returns a single dialog item that packages those two methods into one item. The first method is a UI element that invites the user to drag and drop files onto it to upload them. The second method is a button the user can click to open a dialog for browsing their computer's files and choosing one to upload.
If the user takes either of those actions, when this function calls the
selectFile()
method in the dialog, it will pass a file object with the
file's contents already loaded into it, because the dialog cannot be
expected to read from the user's computer on its own.
Returns
-
Array.<Object>
an array of dialog items, in this case, just one
Source
fileSaverItems()
Overriding the default implementation of fileSaverItems() to return a different UI than the default: This one contains a text blank into which the user can type the filename into which they want to save the document, then click a button to download the file using that filename.
Source
write(fileObject) → {Promise}
See the documentation of the write() method in the parent class for the definition of how this method must behave. It implements the requirements specified there for a file system that represents the user's own computer.
Specifically, "saving" a file really means giving the user the opportunity to download the file to their computer. Consequently, this method will fail if the given file object contains a path, since we cannot dictate where the user must download it. However, you may specify a filename, and it will be the initial suggestion in the download dialog that appears subsequently, but the user can change it thereafter.
An important limitation here is that we do not know whether the user actually accepted the download or not; we simply initiate the process and let the user go from there. Consequently, this function will say that the file is saved, when in reality, we know only that the saving process was initiated, and the user is responsible for the rest. They might cancel the download, and yet the app (not knowing that) thinks that they have saved the file, and will let them close the app without prompting them to save their work, nor auto-saving it for them.
Parameters
-
fileObject
Object
as documented in the FileSystem class
Returns
-
Promise
as documented in the abstract method of the parent class