The Filesystem API allow to read/write access files residing on the device.
Filesystem.writeText({
path: 'anydir/text.txt',
data: "This is a test",
directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function(result) {
console.log('Wrote file', result);
}).catch(function(e) {
console.error('Unable to write file', e);
});
...
Filesystem.readFile({
path: 'anydir/text.txt',
directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function(contents) {
console.log(contents);
}).catch(function(e) {
console.error('Error ', e);
});
...
Filesystem.appendFile({
path: 'anydir/text.txt',
data: "MORE TESTS",
directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function(result) {
console.log('Append to file', result);
}).catch(function(e) {
console.error('Unable to append file', e);
});
...
Filesystem.deleteFile({
path: 'anydir/text.txt',
directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function() {
console.log('File deleted');
}).catch(function(e) {
console.error('Unable to delete file', e);
});
...
Filesystem.mkdir({
path: 'anydir',
directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function() {
console.log('Directory created');
}).catch(function(e) {
console.error('Unable to make directory', e);
});
...
Filesystem.rmdir({
path: 'anydir',
directory: FawiFilesystem.Directories.LOCAL_STORAGE,
recursive: false,
}).then(function() {
console.log('Directory created');
}).catch(function(e) {
console.error('Unable to remove directory', e);
});
...
Filesystem.readdir({
path: 'anydir',
directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function(contents) {
console.log(contents);
}).catch(function(e) {
console.error('Error ', e);
});
...
Filesystem.stat({
path: 'anydir',
directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function(stats) {
console.log(stats);
}).catch(function(e) {
console.error('Error ', e);
});
...
Filesystem.getUri({
path: 'anydir/file.txt',
directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function(uri) {
console.log(uri);
}).catch(function(e) {
console.error('Error ', e);
});
...
Filesystem.rename({
from: 'text.txt',
to: 'text2.txt',
directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function() {
console.log('File renamed');
}).catch(function(e) {
console.error('Unable to rename file', e);
});
...
Filesystem.copy({
from: 'text.txt',
to: 'text2.txt',
directory: FawiFilesystem.Directories.LOCAL_STORAGE
}).then(function() {
console.log('File copied');
}).catch(function(e) {
console.error('Unable to copy file', e);
});
window.Filesystem.mkdir({
path: "anydir",
directory: window.FawiFilesystem.Directories.LOCAL_STORAGE,
})
.then(function () {
console.log("Directory created");
})
.catch(function (e) {
console.error("Unable to make directory", e);
});
...
window.Filesystem.readdir({
path: "anydir",
directory: window.FawiFilesystem.Directories.LOCAL_STORAGE,
})
.then(function (contents) {
console.log(contents);
})
.catch(function (e) {
console.error("Error ", e);
});
window.Filesystem.mkdir({
path: "anydir",
directory: window.FawiFilesystem.Directories.LOCAL_STORAGE,
})
.then(function () {
console.log("Directory created");
})
.catch(function (e) {
console.error("Unable to make directory", e);
});
...
window.Filesystem.readdir({
path: "anydir",
directory: window.FawiFilesystem.Directories.LOCAL_STORAGE,
})
.then(function (contents) {
console.log(contents);
})
.catch(function (e) {
console.error("Error ", e);
});
(<any>window).Filesystem.mkdir({
path: "anydir",
directory: (window).FawiFilesystem.Directories.LOCAL_STORAGE,
})
.then(() => {
console.log("Directory created");
})
.catch(function (e) {
console.error("Unable to make directory", e);
});
...
(<any>window).Filesystem.readdir({
path: "anydir",
directory: (window).FawiFilesystem.Directories.LOCAL_STORAGE,
})
.then(function (contents) {
console.log(contents);
})
.catch(function (e) {
console.error("Error ", e);
});
window.Filesystem.mkdir({
path: "anydir",
directory: window.FawiFilesystem.Directories.LOCAL_STORAGE,
})
.then(function () {
console.log("Directory created");
})
.catch(function (e) {
console.error("Unable to make directory", e);
});
...
window.Filesystem.readdir({
path: "anydir",
directory: window.FawiFilesystem.Directories.LOCAL_STORAGE,
})
.then(function (contents) {
console.log(contents);
})
.catch(function (e) {
console.error("Error ", e);
});
appendFile(options: FileAppendOptions): Promise<any>
Append to a file on disk in the specified location on device.
getUri(options: GetUriOptions): Promise<GetUriResult>
Return full File URI for a path and directory.
readFile(options: FileReadOptions): Promise<FileReadResult>
Read a file from disk.
readdir(options: ReaddirOptions): Promise<ReaddirResult>
Return a list of files from the directory (not recursive).
rename(options: RenameOptions): Promise<any>
Rename a file or directory.
rmdir(options: ReaddirOptions): Promise<any>
Remove a directory.
stat(options: StatOptions): Promise<StatResult>
Return data about a file.
writeFile(options: FileWriteOptions): Promise<FileWriteResult>
Write a file to disk in the specified location on device.
interface FileAppendOptions {
// The data to write
data : string;
// The FilesystemDirectory to store the file in
directory ?: FilesystemDirectory;
// The encoding to write the file in. If not provided, data is written as base64 encoded data.
encoding ?: FilesystemDirectory;
// The filename to write
path : string;
}
interface CopyOptions {
// The FilesystemDirectory containing the existing file or directory
directory ?: FilesystemDirectory;
// The existing file or directory
from : string;
// The destination file or directory
to : string;
// The FilesystemDirectory containing the destination file or directory. If not supplied will use the 'directory' parameter as the destination
toDirectory ?: FilesystemDirectory;
}
interface FileDeleteOptions {
// The FilesystemDirectory to delete the file from
directory ?: FilesystemDirectory;
// The filename to delete
path : string;
}
interface GetUriOptions {
// The FilesystemDirectory to get the file under
directory: FilesystemDirectory;
// The path of the file to get the URI for
path: string;
}
interface GetUriResult {
uri : string;
}
interface MkdirOptions {
// The FilesystemDirectory to make the new directory in
directory ?: FilesystemDirectory;
// The path of the new directory
path : string;
// Whether to create any missing parent directories as well. Defaults to false
recursive ?: boolean;
}
interface FileReadOptions {
// The FilesystemDirectory to read the file from
directory ?: ;
// The encoding to read the file in, if not provided, data is read as binary and returned as base64 encoded data.
encoding ?: ;
// The filename to read
path : string;
}
interface FileReadResult {
data : string;
}
interface ReaddirOptions {
// The FilesystemDirectory to list files from
directory ?: FilesystemDirectory;
// The path of the directory to read
path : string;
}
interface ReaddirResult {
files : string[];
}
interface RenameOptions {
// The FilesystemDirectory containing the existing file or directory
directory ?: FilesystemDirectory;
// The existing file or directory
from : string;
// The destination file or directory
to : string;
// The FilesystemDirectory containing the destination file or directory. If not supplied will use the 'directory' parameter as the destination
toDirectory ?: FilesystemDirectory;
}
interface RmdirOptions {
// The FilesystemDirectory to remove the directory from
directory ?: FilesystemDirectory;
// The path of the directory to remove
path : string;
// Whether to recursively remove the contents of the directory Defaults to false
recursive ?: boolean;
}
interface StatOptions {
// The FilesystemDirectory to get the file under
directory ?: FilesystemDirectory;
// The path of the file to get data about
path : string;
}
interface StatResult {
ctime : number;
mtime : number;
size : number;
type : string;
uri : string;
}
interface FileWriteOptions {
// The data to write
data : string;
// The FilesystemDirectory to store the file in
directory ?: ;
// The encoding to write the file in. If not provided, data is written as base64 encoded data.
encoding ?: ;
// The filename to write
path : string;
// Whether to create any missing parent directories. Defaults to false
recursive ?: boolean;
}
interface FileWriteResult {
uri : string;
}
enum FilesystemDirectory {
// The Cache directory
Cache: "CACHE"
// The Data directory
Data: "DATA"
// The Documents directory
Documents: "DOCUMENTS"
// The external directory
External: "EXTERNAL"
// The external storage directory
ExternalStorage: "EXTERNAL_STORAGE"
}
enum Directories {
Application: "APPLICATION"
Cache: "CACHE"
Data: "DATA"
Documents: "DOCUMENTS"
External: "EXTERNAL"
ExternalStorage: "EXTERNALSTORAGE"
}