Using serverStorage to save data on the Volt Server

AppStudio 6.1 brings a new Volt feature: serverStorage. It lets you save and retrieve data on the Volt server. Here are a few uses:

  • As a backup: Keep critical data in the server, so if the phone gets lost or damaged, information is not lost.
  • Multiple devices: If the user runs your app on multiple devices (desktop included), your app can pick up where it left off with the same data.
  • Support: As the owner of the app, you can examine what is in your user’s serverStorage.
  • Data Sharing: The owner of the app can read and write to users’ serverStorage using a different app. Use this to send specific information to users, or to get data the user has collected.

It’s easy to use. You save and retrieve values using a named key. The values can be of any data type: numbers, strings, arrays or objects. There are no limits on the number of values you keep, nor how big the values can be, other than that they be reasonable. If you need to use a lot of data, check with us at support. Here are some examples:

serverStorage.setItem("SimpleString", "ABCD", done)
serverStorage.setItem("Number", 123, done)
serverStorage.setItem("Array", [1, 2, 3, 4], done)
obj = {firstName: "Eric", lastName: "Cartman"}
serverStorage.setItem("Object", obj, done)

‘done’ is a function which gets called when serverStorage.setValue completes. Since the call has to wait for a server to respond, an asynchronous call is used, so your app does not lock up. setValue will almost always be successful: but can fail if the Volt server is not available, for example, if there is no cell or WiFi coverage. In this case, a timeout message will be returned to the ‘done’ function.

Here’s how to retrieve values:

serverStorage.getItem("SimpleString", callback)
serverStorage.getItem("Number", callback)
serverStorage.getItem("Array", callback)
serverStorage.getItem("Object", callback)

//Sample callback function if you're using JavaScript
function callback(error, data) {
    if (error) {
        console.log(error.message)
    } else {
        console.log(data)
    }
}

'Sample callback function if you're using BASIC
Function callback(error, data)
    if error Then
        console.log(error.message)
    Else
        console.log(data)
    End If
End Function

Here is the output in the Chrome Debugger:

ABCD
123
[1, 2, 3, 4]
Object {firstName: "Eric", lastName: "Cartman"}

As with anything which uses Volt, your app needs to be deployed to Volt (these functions won’t work in a local browser) and you have to be signed into Volt.

More Information

You can find the documentation for serverStorage here. AppStudio includes a sample called Storage which you can run.