Github user riknoll commented on a diff in the pull request: https://github.com/apache/cordova-plugin-file/pull/176#discussion_r58276468 --- Diff: README.md --- @@ -538,3 +540,263 @@ Android also supports a special filesystem named "documents", which represents a * `root`: The entire device filesystem By default, the library and documents directories can be synced to iCloud. You can also request two additional filesystems, `library-nosync` and `documents-nosync`, which represent a special non-synced directory within the `/Library` or `/Documents` filesystem. + +## Sample: Create Files and Directories, Write, Read, and Append files ## + +The File plugin allows you to do things like store files in a temporary or persistent storage location for your app (sandboxed storage). The code snippets in this section demonstrate different tasks including: +* Accessing the file system +* Using cross-platform Cordova file URLs to store your files (see _Where to Store Files_ for more info) +* Creating files and directories +* Writing to files +* Reading files +* Appending files + +## Create a persistent file + +Before you can use the File plugin APIs, you must get access to the file system using `requestFileSystem`. When you do this, you can request either persistent or temporary storage. Persistent storage will not be removed unless permission is granted by the user. + +When you get file system access, access is granted for the sandboxed file system only (the sandbox limits access to the app itself), not for general access to any file system location on the device. For more information about location-specific URLs, see _Where to Store Files_. + +Here is a request for persistent storage. + +>*Note* When targeting devices (instead of a browser), you dont need to use `requestQuota` before using persistent storage. + +``` +window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) { + + console.log('file system open: ' + fs.name); + createPersistentFile("newPersistentFile.txt"); + +}, onErrorLoadFs); +``` + +Once you have access, you generally want to use the Cordova file URLs, like `cordova.file.dataDirectory`, where possible (see _Where to Store Files_). This will hide implementation details related to the file locations. To use a Cordova file URL, call `window.resolveLocalFileSystemURL`. The success callback receives a DirectoryEntry object as input. You can use this object to create or get a file (by calling `getFile`). + +The success callback for `getFile` receives a FileEntry object. You can use this to perform file write and file read operations. + +``` +function createPersistentFile(fileName) { + + // Return a DirectoryEntry using Cordova file URLs. + window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function (dirEntry) { --- End diff -- If you are trying to write a file to the sandboxed storage location, I believe you can just call `fs.root.getFile()` (where `fs` comes from `requestFileSystem`) instead of calling `window.resolveLocalFileSystemURL(cordova.file.dataDirectory, ...)` first.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org For additional commands, e-mail: dev-h...@cordova.apache.org