Skip to content

You are here: Input and Output API

Input and Output API

The Input and Output API enables your app to perform common tasks such as copy, rename, and delete files. This API enables you to browse through file systems and then select multiple files to upload on the server. In addition, the I/O API enables you to manage directories, determine if external storage is available, and so forth.

The Input and Output API, often abbreviated as the I/O API, is composed of the following Namespaces.

voltmx.io.File Namespace

Function Description
voltmx.io.File.copyTo Copies a file to the given destination path.
voltmx.io.File.createDirectory Creates a directory on the file system represented by this file object.
voltmx.io.File.createFile Creates a file on the file system represented by this file object.
voltmx.io.File.exists Checks if the file or directory exists on the file system represented by this file object.
voltmx.io.File.getFilesList Returns voltmx.io.FileList object representing the files and directories available under this file object directory.
voltmx.io.File.isDirectory Checks if this object represents a directory file on the file system.
voltmx.io.File.isFile Checks if this object represents a typical file on the file system but not a directory.
voltmx.io.File.moveTo Moves a file to the given destination path.
voltmx.io.File.read Returns the voltmx.types.RawBytes of this file.
voltmx.io.File.remove Deletes a file or a directory.
voltmx.io.File.rename Renames a file or a directory.
voltmx.io.File.write Writes the given content into the file.

voltmx.io.FileList Namespace

Function Description
voltmx.io.File.item Returns the File object at the specified index in the FileList.

voltmx.io.FileSystem Namespace

Function Description
voltmx.io.FileSystem.browse Provides the ability to browse and select files from your local system.
voltmx.io.FileSystem.copyBundledRawFileTo Copies a bundled file from the application binary to the specified destination path on the device.
voltmx.io.FileSystem.getAppGroupDirectoryPath Retrieves the root path of an app group.
voltmx.io.FileSystem.getApplicationDirectoryPath Returns the application directory path.
voltmx.io.FileSystem.getCacheDirectoryPath Returns the application's cache directory path.
voltmx.io.FileSystem.getDatabaseDirectoryPath Returns the application's database directory path (from application's private file system) where voltmx.db APIs access the database files.
voltmx.io.FileSystem.getDataDirectoryPath Returns the application’s data directory path.
voltmx.io.FileSystem.getExternalCacheDir Returns the absolute path to the directory on the primary shared or external storage device where the application can store its cached files.
voltmx.io.FileSystem.getExternalCacheDirs Returns the absolute paths to the application-specific directories on all the shared or external storage devices where the application can store its cached files.
voltmx.io.FileSystem.getExternalFilesDir Returns the absolute path to the directory on the primary shared or external storage device where the application can store its persistent files.
voltmx.io.FileSystem.getExternalFilesDirs Returns the absolute paths to the application-specific directories on all the shared or external storage devices where the application can store its persistent files.
voltmx.io.FileSystem.getExternalStorageDirectoryPath Returns the path to the external storage, typically sdcard.
voltmx.io.FileSystem.getExternalStorageState Returns the current state of the shared or external storage media at the specified path.
voltmx.io.FileSystem.getFile Returns a voltmx.io.File object representing the file for the given path.
voltmx.io.FileSystem.getFileSystemStats Retrieves the detailed information about the space on a file system.
voltmx.io.FileSystem.getNoBackupFilesDir Returns the absolute path to the directory on the file system
voltmx.io.FileSystem.getRawDirectoryPath Returns the application’s “raw” directory path.
voltmx.io.FileSystem.getSupportDirectoryPath Returns the application’s support directory path.
voltmx.io.FileSystem.isExternalStorageAvailable Checks if the external storage is available and accessible on the device.
voltmx.io.FileSystem.isExternalStorageEmulated Checks if the external storage is emulated.
voltmx.io.FileSystem.isExternalStorageRemovable Checks if the external storage is physically removable.
voltmx.io.FileSystem.uploadFiles Internally iterates through the fileList and makes the network call to the URL mentioned and uploads the files.

voltmx.types Namespace

Function Description
voltmx.types.RawBytes.clear Clears the content that is held by the RawBytes object.
voltmx.types.RawBytes.getContentType Retrieves the Content Type of the RawBytes object.
voltmx.types.RawBytes.getResourcePath Returns the location of rawbytes which can be Android content URI or a file path.
voltmx.types.RawBytes.getTempPath Returns the path where the source files of all RawBytes are stored.
voltmx.types.RawBytes.readAsText Returns the data as text represented by the RawBytes object.

File Handling

The voltmx.io.File Namespace consists of functions that enable you to perform common file handling tasks. Your app can create a File object to represent files in the device's file system and perform common operations on them. Now create a file using the voltmx.io.File.createFile function. To verify if a file exists in the file system using the voltmx.io.File.exists function. You can also check if the object represents a file or a directory using the voltmx.io.File.isFile and the voltmx.io.File.isDirectory functions; and return all the files in the filesystem using the voltmx.io.File.getFilesList function.

To move a file, use the voltmx.io.File.moveTo function. To copy a selected file use the voltmx.io.File.copyTo function. You can read the data in the file using the voltmx.io.File.read and the voltmx.io.File.readAsText functions. You can also write in a file using voltmx.io.File.write function. If you want to rename a file, use the voltmx.io.File.rename function; and to delete a file, use the voltmx.io.File.remove function. Using the voltmx.io.File.item, you can return a file object at a specified index in the File list.

File System Handling

The voltmx.io.FileSystem Namespace consists of the functions that handles a file system. Use the voltmx.io.FileSystem.getFile function to get an instance of a File object. You can browse and select files from the file system using the voltmx.io.FileSystem.browse function. Then get the root path of an application using the voltmx.io.FileSystem.getApplicationDirectoryPath and the app group directory path using the voltmx.io.FileSystem.getAppGroupDirectoryPath function. Use the voltmx.io.FileSystem.getCacheDirectoryPath function to get the application cache’s directory path, the voltmx.io.FileSystem.getDataDirectoryPath to get the application’s directory path, the voltmx.io.FileSystem.getDatabaseDirectoryPath to get the application’s database directory path and external storage directory path using the voltmx.io.FileSystem.getExternalStorageDirectoryPath function. For the application’s raw directory path, use the voltmx.io.FileSystem.getRawDirectoryPath function and for the application’s support path, use the voltmx.io.FileSystem.getSupportDirectoryPath function. You can also check if the external storage is available and accessible on the device using the voltmx.io.FileSystem.isExternalStorageAvailable function, and upload files using the voltmx.io.FileSystem.uploadFiles function.

Pre bundling Files

Volt MX gives an ability to bundle files such as SQLite database (pre-configured), video, image, and so on as part of an application binary. After bundling, the files can be accessed from the app at the run time on the device. You need to follow certain guidelines to bundle the files.

Here are the guidelines:

  1. Place the files to be bundled in the application workspace at the following locations. When you place the files in these locations, the files will be bundled with the application built for all the platforms.

    Mobile:

    <WorkSpace>\<App>\resources\mobile\common\raw

    Tablet:

    <WorkSpace>\<App>\resources\tablet\common\raw

  2. You can also place the files in the platform-specific folders. When you place the files in platform-specific folders, the files will be bundled only with the application built for that particular platform. For example, if you place the files in the android\raw folder, the files will be bundled only for the application built for the Android platform.

    Android Mobile:

    <WorkSpace>\<App>\resources\mobile\native\android\raw

    Android Tablet:

    <WorkSpace>\<App>\resources\tablet\native\androidtab\raw

    IOS Mobile:

    <WorkSpace>\<App>\resources\mobile\native\iphone\raw

    IOS Tablet:

    <WorkSpace>\<App>\resources\tablet\native\ipad\raw

    Windows 10:

    <WorkSpace>\<App>\resources\tablet\native\windows8\raw

    After placing the files either in common or platform-specific folder and build the respective application, the files are packaged in the application binary file. Example, .apk, .ipa, and so on.

    In case same file is located at both common and platform-specific folders, the file in the platform-specific folder will override the file in the common folder.

  3. In case of Android, the file name should contain only the following characters:

    • a – z (lower case)
    • 0 – 9
    • _ (underscore)
    • . (period)

    This guideline is applicable only for the Android platform.

  4. Application binary size limitation: After bundling the files, the size of the application binary should not exceed the size defined for each platform in the table below. These size limits are specified by the platform-specific stores where the apps will be uploaded.

Note: In future these values may vary based on the application store decisions for respective platforms.
OS Limit Binary Type
Android 100 MB .apk
IOS 60 MB .ipa
Windows 25 GB .appxbundle
Silver light applications 1 GB .xap packages

Volt MX Iris provides the following APIs to support accessing the pre-bundled files programmatically.