Using serverStorage to save your data

ServerStorage is an easy new way to save data in your AppStudio App. It works just like localStorage, but instead of saving the data locally on your device, it saves to the server.

This opens up many new possibilities: Companies could upload and download data, teachers could publish information for students, games could share scores or moves. It could even be used as a backup in the cloud.

Read the wiki article to get full details on how to use it.

It requires some additional software to be configured on the server. The nsbapp.com server is ready to use it now: we will be providing instructions on how to add this to your own server. It will only run on apps deployed to a server: it will not work locally.

In its simplest form, save data to the server like this:

serverStorage.setItem("20141110","The weather today is sunny.")

Next time you run your app, even if it is on a different device, you can do this:

data = serverStorage.getItem("20141110")
MsgBox data

and you will get this:
Capture

Normally, data is saved in a namespace using the app’s id. However, it is possible to set the namespace to any string, allowing apps to share data.

We could have a Teacher App which saves the following information to serverStorage:

serverStorage.namespace = "ClassroomNews"
serverStorage.setItem("Homework","Today's Math homework is chapter 3")
serverStorage.setItem("Announcement","Assembly is at 11:00.")

A Student App could read the news as follows:

serverStorage.namespace = "ClassroomNews"
For i=0 To serverStorage.length-1
  key = serverStorage.key(i)
  Print key, serverStorage.getItem(key)
Next

and see this…
Capture

Any kind of string data can be saved. Numbers are converted automatically to strings. Arrays and objects can be converted to strings using JSON.Stringify and JSON.Parse:

serverStorage.setItem("myObject", JSON.Stringify(myObject)
myObject = JSON.Parse(serverStorage.getItem("myObject"))

Images from a PictureBox can be saved in Base64 format:

serverStorage.setItem("myPicture", PictureBox1.toDataURL())

Another use would be for multi player games. High scores or even real time game data could be saved to the server. The players could get the latest information about other players moves in real time and react to them.

ServerStorage is insecure: there is currently no protection against other apps reading or changing the data. If two apps are using the same namespace, there is no collision or locking logic: it is possible for one user to erase another user’s update.