Skip to main content

File System

buildfire.services.fileSystem.fileManager#

File Services are services that allow you to access the file system in a limited and secure way.

Info

This service works only on devices

Requirements#

Widget#

Include fileManager.js file in widget header right after the buildfire.min.js

<head>
<!-- ... -->
<script src="../../../scripts/buildfire/buildfire.min.js"></script>
<script src="../../../scripts/buildfire/services/fileSystem/fileManager.js"></script>
</head>

Methods#

download()
#

buildfire.services.fileSystem.fileManager.download(options, callback)

This method allows you to download a file from a URI to the local persistent file system

var options = {};
function fileDownloaded(error, filePath) {}
buildfire.services.fileSystem.fileManager.download(
{
uri:
"http://www.filltext.com/?rows=10&fname={firstName}&lname={lastName}&pretty=true",
path: "/data/people/",
fileName: "managers.json",
},
(err, filePath) => {
if (err) return console.error(err);
console.log("Downloaded File to ", filePath);
}
);

options#

NameTypeRequiredDescriptionDefault
uristringyesUrl of file to download to local filesystem ex. https://.../image.png
pathstringyeswhere to download the file ex. /cache/images
fileNamestringyesThe name of downloaded file

callback(err, filePath)#

Callback function that will be called when the download is complete

NameTypeDescription
errstringerror string, null when operation is successfull
filePathstringThe 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

buildfire.services.fileSystem.fileManager.readFileAsText(
{ path: "/data/people/", fileName: "managers.json" },
(err, fileContent) => {
if (err) return console.error(err);
console.log("File content", fileContent);
}
);

options#

NameTypeRequiredDescriptionDefault
pathstringyesFile local path
fileNamestringyesName of the file to read

callback(err, fileContent)#

Callback function after the file has been read

NameTypeDescription
errstringerror string, null when operation is successfull
fileContentstringContents of a file

writeFileAsText()
#

buildfire.services.fileSystem.fileManager.writeFileAsText(options, callback)

This method allows you to write to a file in the local persistent file system

buildfire.services.fileSystem.fileManager.writeFileAsText(
{
path: "/data/people/",
fileName: "names.txt",
content: "Daniel, Isabelle, Christian",
},
(err, isWritten) => {
if (err) return console.error(err);
console.log("File is written");
}
);

options#

NameTypeRequiredDescriptionDefault
pathstringyesFiles local path
fileNamestringyesName of the file to write to
contentstringyesContent to write to file
appendbooleannoTo append to existing file or overwrite itfalse

callback(err, isWritten)#

Callback function after writing to file is complete

NameTypeDescription
errstringerror string, null when operation is successfull
isWrittenbooleanIndicates whether writing to file was successfull

deleteFile()
#

buildfire.services.fileSystem.fileManager.deleteFile(options, callback)

This method allows you to delete a file in the local persistent file system

buildfire.services.fileSystem.fileManager.deleteFile(
{ path: "/data/people/", fileName: "managers.json" },
(err, isDeleted) => {
if (err) return console.error(err);
if (isDeleted) console.log("File is deleted");
}
);

options#

NameTypeRequiredDescriptionDefault
pathstringyesFile local path
fileNamestringyesName of the file to delete

callback(err, isDeleted)#

Callback function after file is delete

NameTypeDescription
errstringerror string, null when operation is successfull
isDeletedbooleanIndicates if file was deleted successfully