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”).
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
Provide a path to save data at.
dataToSave
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
Provide a path to insert data at.
dataToInsert
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
Provide a path to update data at.
dataToUpdate
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
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
Provide a path to listen for data additions and changes at.
options
listenOption
‘NEW_DATA’ : To listen to new data added to the location.
‘UPDATED_DATA’ : To listen to changes to existing data at the location.
orderByValue
Set to true, to order the callback by the value of the children at the location.
orderByField
Order the callback by the value of the field in the children at the location.
limitToFirst
Limit the callback to the first certain number of matching children.
limitToLast
Limit the callback to the last certain number of matching children.
startsWith
Return children whose String value starts with the ‘value’ specified.
equals
Return children equal to the ‘value’ specified.
maxValue
Return children whose numeric value is lesser than or equal to the ‘maxValue’.
minValue
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
Provide the path to retrieve data from.
options
orderByValue
Set to true, to order the retrieved data by the value of the children at the location.
orderByField
Order the retrieved data by the value of the field in the children at the location.
limitToLast
Limit the retrieved data to the first certain number of matching children.
limitToLast
Limit the retrieved data to the last certain number of matching children.
startsWith
Return data whose String value starts with the ‘value’ specified.
equals
Return data equal to the ‘value’ specified.
maxValue
Return data whose numeric value is less than or equal to the ‘maxValue’.
minValue
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
Provide the path to stop listening at for data additions and changes.
options
listenOption
‘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
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);
callId
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
);
callId
Use the same callId used during selectFile to upload that File.
path
Provide a path to save File at.
options
tagsArray
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
Optionally, you can rename the file selected to any other name you want by setting this field.
fileType
Optionally, you can rename the fileType selected to any other type you want by setting this field.
uploadSizeLimit
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.
{
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);
}
);
callId
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);
callId
Use the same callId used during uploadFile to stop that upload.
onymosUtil.searchFile
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
);
tagsArray
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
The fileURI (secure URL) returned by this searchFile function, will be valid only for the number of seconds specified in this parameter.
searchResultsLimit
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.
{
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
Provide the path to retrieve File from.
options
resultsValidityTime
The fileUrl (secure URL) returned by this getFile function, will be valid only for the number of seconds specified in this parameter.
{
resultsValidityTime: 1800
}