File System
buildfire.services.fileSystem.fileManager
#
The File System Service provides secure access to the file system.
Info
This service works only on devices
#
Requirements#
WidgetInclude fileManager.js
file in widget header, after the buildfire.min.js
tag.
#
Methodsdownload()
#
buildfire.services.fileSystem.fileManager.download(options, callback)
This method allows you to download a file from a URI to the local persistent file system
tip
You can add onProgress
parameter to track the file download progress.
buildfire.services.fileSystem.fileManager.download(options, onProgress, callback)
options
#
Name | Type | Required | Description | Default |
---|---|---|---|---|
uri | string | yes | Url of the file to download to the local filesystem, ex. https://.../image.png | |
path | string | yes | Destination path for the file, ex. /cache/images | |
fileName | string | yes | The name of downloaded file |
onProgress
#
Function that will be invoked repeatedly while the operation is in progress, returns a percentage
property representing the current progress of the operation.
Name | Type | Description |
---|---|---|
onProgress | function | Function that will be invoked repeatedly while the operation is in progress, returns a percentage property representing the current progress of the operation |
callback(err, filePath)
#
Callback function that will be called when the download is complete
Name | Type | Description |
---|---|---|
err | string | Error string, null when operation is successful |
filePath | string | The local path to the downloaded file |
readFileAsText()
#
buildfire.services.fileSystem.fileManager.readFileAsText(options, callback)
This method allows you to read a file in the local persistent file system
options
#
Name | Type | Required | Description | Default |
---|---|---|---|---|
path | string | yes | File local path | |
fileName | string | yes | Name of the file to read |
callback(err, fileContent)
#
Callback function after the file has been read
Name | Type | Description |
---|---|---|
err | string | Error string, null when operation is successful |
fileContent | string | Contents of the file |
writeFileAsText()
#
buildfire.services.fileSystem.fileManager.writeFileAsText(options, callback)
This method allows you to write to a file in the local persistent file system
options
#
Name | Type | Required | Description | Default |
---|---|---|---|---|
path | string | yes | File local path | |
fileName | string | yes | Name of the file to write to | |
content | string | yes | Content to write to the file | |
append | boolean | no | To append to existing file or overwrite it | false |
callback(err, isWritten)
#
Callback function after writing to file is complete
Name | Type | Description |
---|---|---|
err | string | Error string, null when operation is successful |
isWritten | boolean | Indicates whether writing to file was successful |
deleteFile()
#
buildfire.services.fileSystem.fileManager.deleteFile(options, callback)
This method allows you to delete a file in the local persistent file system
options
#
Name | Type | Required | Description | Default |
---|---|---|---|---|
path | string | yes | File local path | |
fileName | string | yes | Name of the file to delete |
callback(err, isDeleted)
#
Callback function after file is delete
Name | Type | Description |
---|---|---|
err | string | Error string, null when operation is successful |
isDeleted | boolean | Indicates if file was deleted successfully |