-
Notifications
You must be signed in to change notification settings - Fork 84
File System Services
This sdk documentation is deprecated and will not be updated. Check out our new docs at https://sdk.buildfire.com/docs/file-system/
File Services are services that allow you to access the file system in a limited and secure way.
NOTE: This only works on the device. You cannot use this on the Control side of a plugin nor- on the web version of the widget
Must include:
<script src="../../../scripts/buildfire/services/fileSystem/fileManager.js"></script>
this method allows you to download a file from a URI to the local persistent file system
-
optionsis an object parameter consisting of the following properties-
uri: url to download example: 'https://.../image.png' -
path: where to download the file (remember this cant be anywhere on the device) example: '/cache/images' -
fileName: what to call the file example: 'logo.png'
-
-
callback(error, filePath)This is a function that will be called back when the download is complete with the local path to the downloaded file-
error: object consisting of the error encountered while executing -
filePath: the local path to the downloaded file
-
var options = {
uri:"http://www.filltext.com/?rows=10&fname={firstName}&lname={lastName}&pretty=true"
,path:"/data/people/"
,fileName:"managers.json"
}
function fileDownloaded(error, filePath){
if(error)
console.error("failed to download due to ",error)
else
console.log("Downloaded File to ", filePath)
}
buildfire.services.fileSystem.fileManager.download(options, fileDownloaded );
this method allows you to delete a file in the local persistent file system
-
optionsis an object parameter consisting of the following properties-
path: where the file is (remember this cant be anywhere on the device) example: '/cache/images' -
fileName: which file to delete example: 'logo.png'
-
-
callback(error, successFlag)This is a function that will be called back when the delete is complete-
error: object consisting of the error encountered while executing -
successFlag:trueif deleted
-
var options = {
path:"/data/people/"
,fileName:"managers.json"
}
function fileDeleted(error){
if(error)
console.error("failed to delete file due to ",error)
else
console.log("Deleted File")
}
buildfire.services.fileSystem.fileManager.deleteFile(options, fileDownloaded );
this method allows you to read a file in the local persistent file system
-
optionsis an object parameter consisting of the following properties-
path: where the file is (remember this cant be anywhere on the device) example: '/cache/data' -
fileName: which file to read example: 'names.txt'
-
-
callback(error, fileContent)This is a function that will be called back when the file has been read or failed to read-
error: object consisting of the error encountered while executing -
fileContent: string of content
-
var options = {
path:"/data/people/"
,fileName:"managers.json"
}
function gotContent(error, fileContent){
if(error)
console.error("failed to read file due to ",error);
else
console.log("File Content: ",fileContent);
}
buildfire.services.fileSystem.fileManager.readFileAsText(options, gotContent );
this method allows you to write to a file in the local persistent file system
-
optionsis an object parameter consisting of the following properties-
path: where the file is (remember this cant be anywhere on the device) example: '/cache/data' -
fileName: which file to read example: 'names.txt' -
content:stringto write to file -
append:boolto append to existing file contents or overwrite it
-
-
callback(error, flag)This is a function that will be called back when the file has been written or failed to write-
error: object consisting of the error encountered while executing -
flag:trueif written successfully
-
var options = {
path:"/data/people/"
,fileName:"names.txt"
,content: "Daniel, Isabelle, Christian"
}
function fileWritten(error){
if(error)
console.error("failed to write file due to ",error);
else
console.log("File Written");
}
buildfire.services.fileSystem.fileManager.writeFileAsText(options, fileWritten );