requestFileSystem() vs resolveLocalFileSystemURL()


.

When you get file system access using requestFileSystem, 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. (read here for TEMPORARY and here for PERSISTENT storage tutorial)

To access file system locations outside the sandboxed storage, use other methods such as window.requestLocalFileSystemURL, which support platform-specific locations. 

As of Cordova v1.2.0 (cordova-plugin-file), URLs to important file-system directories are provided. Each URL is in the form file:///path/to/spot/, and can be converted to a DirectoryEntry using window.resolveLocalFileSystemURL(). (read here)
.

Methods

requestFileSystem()

Requests a file system where data should be stored. You access a sandboxed file system by requesting a LocalFileSystem object using this global method, window.requestFileSystem().
void requestFileSystem(
  in unsigned short type, 
  in unsigned long long size, 
  in FileSystemCallback successCallback, 
  in ErrorCallback errorCallback
);
Parameters
type
The storage type of the file system. The values can be either TEMPORARY or PERSISTENT.
size
The storage space—in bytes—that you need for your app.
successCallback
The success callback that is called when the browser provides a file system. Its argument is the FileSystem object with two properties:
  • name - the unique name assigned by the browser to the file system.
  • root - the read-only DirectoryEntry object representing the root of the file system.
opt_errorCallback
The error callback that is called when errors happen or when the request to obtain the file system is denied. Its argument is the FileError object.
Returns
void
Exceptions
This method can raise an FileError with the following code:
ExceptionDescription
SECURITY_ERRORThe application does not have permission to access the file system interface. For example, you cannot run from file://. For more details, see the article on basic concepts.

resolveLocalFileSystemURL()

Lets you look up the entry for a file or directory with a local URL.
void resolveLocalFileSystemURL(
  in DOMString url, 
  in EntryCallback successCallback, 
  in optional ErrorCallback errorCallback
);
Parameters
url
The URL of a local file in the file system.
successCallback
The success callback that is called when the browser provides the file or directory for the supplied URL.
errorCallback
The error callback that is called when errors happen or when the request to obtain the entry object is denied.
Returns
void
Exceptions
This method can raise an FileError with the following code:
ExceptionDescription
ENCODING_ERRThe syntax of the URL was invalid.
NOT_FOUND_ERRThe URL was structurally correct, but refers to a resource that does not exist.
SECURITY_ERRThe application does not have permission to access the file system interface.

.
REFERENCE:
1. https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/index.html
2. https://developer.mozilla.org/en-US/docs/Web/API/LocalFileSystem
.

0 Comments: