Trigger API: File Management

This API allows you to check to see if a file exists in the Kiosk Pro Documents folder and also to delete files.

Functions

Requirements

  • Access JavaScript API
    • By Import - recommended, works both online & offline, requires inclusion of kiosk_functions.js prior to any of the following calls.
    • By Injection - only works offline, may not be available 'onload'.

Sample Code

This sample code relies on the JavaScript APIs built into Kiosk Pro and will not run successfully in other browsers or within our in-app help interface.  
To run sample code, set the app's homepage to  http://www.kioskproapp.com/file-management

fileExists

This function checks whether a file exists in Kiosk Pro's Documents folder.

Format
fileExists(fileName,callback);
		
Parameters
  • fileName = name of the .csv or .txt file to check as a string. If the file is located in a subfolder, that path must be included with the file name.
  • callback = name of callback function which will be called with the following signature: callback(success).
Callback format
callback(success);
		
Callback return values success = if defined, the files exists.

deleteFile

This function deletes a file stored locally in Kiosk Pro's Documents folder.

Format
deleteFile(fileName,callback);
		
Parameters
  • fileName = name of the .csv or .txt file to delete as a string. If the file is located in a subfolder, that path must be included with the file name.
  • callback = name of callback function which will be called with the following signature: callback(success).
Callback format
callback(success);
		
Callback return values success = if defined, the file has been deleted.

kp_FileAPI_renameFile

This function allows you to rename any locally stored file in Kiosk Pro's Documents folder.

Format
kp_FileAPI_renameFile(oldFileName, newFileName, callback)
		
Parameters
  • oldFileName = name of the existing .csv or .txt file to rename as a string. If the file is located in a subfolder, that path must be included with the file name.
  • newFileName = new name of the .csv or .txt file as a string. If the file is located in a subfolder, that path must be included with the file name.
  • callback = name of callback function which will be called with the following signature: callback(success).
Callback format
callback(success);
		
Callback return values success = if defined, the file was renamed successfully.

kp_FileAPI_base64FromFile

Added in version 7.5

This function returns the appropriate base64 string for any locally stored file in Kiosk Pro's Documents folder. This can be useful when your content is hosted remotely, but you require access to a file that is stored locally on the device - for example, if you wanted to use the Snap API to take a picture and then upload the result to a server (sample code taking a picture and returning a base 64 string available  here).

Format
kp_FileAPI_base64FromFile(fileName, callback);
		
Parameters
  • fileName = name of the file to convert to Base64 as a string. If the file is located in a subfolder, that path must be included with the file name.
  • callback = name of callback function which will be called with the following signature: callback(success).
Callback format
callback(base64Str, error);
		
Callback return values base64Str = possible values include:
  • string without line endings representing the base 64 value of the file.
  • null if there is an error during the operation.
  • empty if file does not exist.

error = possible values include:

  • null if there is no error during the operation.
  • an array with the format {'domain':'...', 'code':'...', 'description':'...'}.

Still stuck? How can we help? How can we help?