The easiest way to integrate Payments in your app is here: Learn more

onymos-logo

These data storage functions are optional. If you choose to use Onymos Hosting, these functions are used to get and put data into the Onymos Cloud. Onymos customers can bring their own cloud data storage as well.

When you’re writing paths, remember that DataStore keeps the base path under the hood, and the path you write can be whatever you want (e.g., “stores/locations”). The Onymos Cloud will automatically generate the location for you if it doesn’t exist already.

onymosUtil.addData

To add data to a particular path. Previous data at the path location will be over-written.

OnymosUtil.addData(
path,
dataToSave,
(statusMessage) => {
console.log(statusMessage);
},
(error) => {
console.log(error);
}
);
path

Path

Provide a path to save data at.

dataToSave

JSON Object

Provide data in JSON object format to save.

onymosUtil.insertData

To insert data at a particular path. A new unique child location is created, and the provided data is added at the child location. The path to the child location is returned in the successCallback.

OnymosUtil.insertData(
path,
dataToInsert,
(childPath) => {
console.log(childPath);
},
(error) => {
console.log(error);
}
);
path

Path

Provide a path to insert data at.

dataToInsert

JSON Object

Provide data in JSON object format to insert.

onymosUtil.updateData

To update data at a particular path. Only the enumerated data is modified, leaving all other data untouched.

OnymosUtil.updateData(
path,
dataToUpdate,
(statusMessage) => {
console.log(statusMessage);
},
(error) => {
console.log(error);
}
);
path

Path

Provide a path to update data at.

dataToUpdate

JSON Object

Provide data in JSON object format to update.

onymosUtil.deleteData

To delete data at a particular path.

OnymosUtil.deleteData(
path,
(statusMessage) => {
console.log(statusMessage);
},
(error) => {
console.log(error);
}
);
path

Path

Provide a path to delete data at.

onymosUtil.listenForData

To listen to data additions or changes at a particular path.

OnymosUtil.listenForData(
path,
(data) => {
console.log(data);
}
(error) => {
console.log(error);
},
options
);
path

Path

Provide a path to listen for data additions and changes at.

options
listenOption

string

‘NEW_DATA’ : To listen to new data added to the location.
‘UPDATED_DATA’ : To listen to changes to existing data at the location.

orderByValue

Boolean

Set to true, to order the callback by the value of the children at the location.

orderByField

string

Order the callback by the value of the field in the children at the location.

limitToFirst

Number

Limit the callback to the first certain number of matching children.

limitToLast

Number

Limit the callback to the last certain number of matching children.

startsWith

Value

Return children whose String value starts with the ‘value’ specified.

equals

Value

Return children equal to the ‘value’ specified.

maxValue

Value

Return children whose numeric value is lesser than or equal to the ‘maxValue’.

minValue

Value

Return children whose numeric value is greater than or equal to the ‘minValue’.

onymosUtil.getData

To retrieve data from a particular path.

OnymosUtil.getData(
path,
(data) => {
console.log(data);
},
(error) => {
console.log(error);
},
options
);
path

Path

Provide the path to retrieve data from.

options
orderByValue

Boolean

Set to true, to order the retrieved data by the value of the children at the location.

orderByField

String

Order the retrieved data by the value of the field in the children at the location.

limitToLast

Number

Limit the retrieved data to the first certain number of matching children.

limitToLast

Number

Limit the retrieved data to the last certain number of matching children.

startsWith

Value

Return data whose String value starts with the ‘value’ specified.

equals

Value

Return data equal to the ‘value’ specified.

maxValue

Value

Return data whose numeric value is less than or equal to the ‘maxValue’.

minValue

Value

Return data whose numeric value is greater than or equal to the ‘minValue’.

onymosUtil.stopListenForData

To stop listening for the additions or changes at a particular path. This function detaches the callback previously associated using the OnymosUtil.listenForData call.

OnymosUtil.stopListenForData(
path,
(statusMessage) => {
console.log(statusMessage);
},
(error) => {
console.log(error);
},
options
);
path

Path

Provide the path to stop listening at for data additions and changes.

options
listenOption

string

‘NEW_DATA’ : To stop listening to new data added to the location.
‘UPDATED_DATA’ : To stop listening to changes to existing data at the location.

onymosUtil.selectFile

To access files in the device, we call the select function, usually in response to an event like clicking on a Select icon.

OnymosUtil.selectFile(
callId,
(fileObject) => {
/* ------
fileObject = {
fileName: File name,
fileSize: Size in megabytes,
fileType: Type of file,
fileURI: Local file path
};
------ */
},
(error) => {
console.log(error);
},
options
);
callId

string

To identify each call to selectFile. In most cases, only one invocation will be required, and so use ‘1’.
A special case example is, if your app has ‘Your Resume, ‘Your cover letter’, with separate file select icons next to each to select each file, use callId of ‘1’, and ‘2’.

onymosUtil.cancelSelectFile

To cancel the previously made selection, we call the cancelSelectFile function, usually in response to an event like clicking on a Cancel icon.

This call clears the callId and removes the association with the selected File. In addition this function also clears the selected File URI and all intermediate media stores to clear valuable memory space in your app.

OnymosUtil.cancelSelectFile(callId);
Note: This is a synchronous call and clears valuable memory space in your app.
callId

string

Use the same callId used during selectFile to cancel that selection.

onymosUtil.uploadFile

To upload the selected File to Onymos Hosting, we call the uploadFile function, usually in response to an event like clicking on a Send button.

OnymosUtil.uploadFile(
callId,
path,
(statusMessage) => {
console.log(statusMessage);
},
(error) => {
console.log(error);
},
options
);
Note: This is a synchronous call and clears valuable memory space in your app.
callId

string

Use the same callId used during selectFile to upload that File.

path

Path

Provide a path to save File at.

options
tagsArray

String

Optionally, you can also associate each File with a list of up to 5 tags, that you can later use to find the File with. Most frequently, an unique ID is used as a tag with each File to identify the File later.
Array of Strings: Up to 5 strings (at least 1 is required) can be used to tag a File. These set of tags will be used to find File later. Most frequently, a unique Id alone is used as a Tag. However, you can use something like,
var tagsArray = ‘Fast, Red, European, Car’.split(/[\s,]+/);

Note:
tagsArray strings cannot contain ASCII control characters 0-31, 127, and any of “$,   #,   /,   .,   {,   },   [,   ],   (,   )” characters.
tagsArray strings cannot be longer than 512 characters.

fileName

String

Optionally, you can rename the file selected to any other name you want by setting this field.

fileType

String

Optionally, you can rename the fileType selected to any other type you want by setting this field.

uploadSizeLimit

Number

For performance and stability reasons, as well as your app users’ experience (time taken to upload, memory/cpu/network used, etc.,), you can specify a value in MB (Megabytes) that you want to restrict the upload file to. If a file to be uploaded exceeds this uploadSizeLimit this uploadFile function will return an error.

Usage Example

{
fileName: ‘myNewFileName’,
fileType: ‘pdf’,
uploadSizeLimit: 15
}

onymosUtil.getUploadProgress

To track the progress of a previous Upload call, we call the getUploadProgress function, usually right after a call to the uploadFile function.

OnymosUtil.getUploadProgress(
callId,
(statusObject) => {
/* ------
statusObject = {
percent: Percentage or -1, if total is being determined,
uploaded: Size in bytes,
total: Size in bytes or 'Determining...'
};
------ */
},
(error) => {
console.log(error);
}
);
Note: This function will return a failure, if the Upload is already complete and all items associated with the callId are cleared after the Upload.
callId

String

Use the same callId used during uploadFile to track progress of that upload.

onymosUtil.stopUploadFile

To stop an Upload currently in-progress, we call the stopUploadFile function, usually in response to an event like clicking on a Stop icon.
Upon a successful stop, the failureCallback of the uploadFile function will trigger with an error message, that the upload ‘Request is aborted by user’.

OnymosUtil.stopUploadFile(callId);
Note: This is a synchronous call and returns nothing. When successful, the failureCallback of the uploadFile function will trigger.
callId

String

Use the same callId used during uploadFile to stop that upload.

onymosUtil.searchFileSuccess

To find previously uploaded File at either Onymos Hosting or your cloud hosting provider, we call the searchFile function.

OnymosStorage.searchFile(
tagsArray,
(resultsArray) => {
/* ------
resultsArray = [{
fileName: File name,
fileSize: Size in megabytes,
fileType: Type of file,
fileURI: Local file path,
uploadTime: Unix epoch time
}];
------ */
},
(error) => {
console.log(error);
},
options
);
Note: This searchFile function is usable only if you have either purchased Onymos Hosting or specified your own cloud hosting access credentials in the initialize function.
tagsArray

String

Array of Strings: Up to 5 strings (at least 1 is required) can be used to search for a File. Most frequently, a unique Id alone is used as a Tag. However, you can use something like,
var tagsArray = ‘Fast, Red, European, Car’.split(/[\s,]+/);

Note:
tagsArray strings cannot contain ASCII control characters 0-31, 127, and any of “$,   #,   /,   .,   {,   },   [,   ],   (,   )” characters.
tagsArray strings cannot be longer than 512 characters.

options
resultsValidityTime

Number

The fileURI (secure URL) returned by this searchFile function, will be valid only for the number of seconds specified in this parameter.

searchResultsLimit

Number

For your app’s search performance, you can limit the number of results returned by this searchFile function, by setting an integer value to this parameter.

Usage Example

{
resultsValidityTime: 1800,
searchResultsLimit: 5
}

onymosUtil.getFile

To retrieve previously uploaded File at Onymos Hosting or your cloud hosting provider, we call the getFile function.

OnymosUtil.getFile(
path,
(fileUrl) => {
console.log(fileUrl);
},
(error) => {
console.log(error);
},
options
);
path

Path

Provide the path to retrieve File from.

options
resultsValidityTime

Number

The fileUrl (secure URL) returned by this getFile function, will be valid only for the number of seconds specified in this parameter.

Usage Example

{
resultsValidityTime: 1800
}

Think differently about app development

Download our free white paper today to learn how Onymos Features can maximize the value of your developer resources — and shave days or weeks off your development timeline.

Get your free white paper