Using CloudMine to store your application data in the cloud

Saturday, October 6, 2012 Posted by Ruslan Matveev
Nowadays HTML5 becomes more and more popular, offline cache can help you when you need to build an application that does not require a web - server, client - side storage can be used to store application data in built - in web - browser database. But what if you need to share application data between users? There are many web - applications that allows you to share your work with the rest of the world, for example jsFiddle allows you to save your code snippet and get a permanent link that you can post in twitter or send to your friend. So how can you make something like this using HTML and JavaScript only?

CloudMine provides you with with the remote storage that you can use in your web - application to store settings or any other kind of data. Important point is that you don't need to have a backend in order to communicate with CloudMine service, all you need is JavaScript! So here is what you have to do before coding:

  1. 1. Sign up for account here: https://cloudmine.me/pricing/signup
  2. 2. Go to the Dashboard and create an application: https://cloudmine.me/dashboard/app/create
And now it's a time to write some code, put this two script tags on your page:

<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://cloud.github.com/downloads/cloudmine/cloudmine-js/cloudmine-0.9.4.min.js"></script>

Initialize CloudMine WebService instance with the Application ID and API key (find them on the application preference page in the Dashboard):

<script type="text/javascript">
    var cloudMine = new cloudmine.WebService({
        appid: 'Application ID',
        apikey: 'API key'
    });
</script>

Now you can save any JavaScript value into the cloud using following snippet:

<script type="text/javascript">
    ws.set(
        // key
        'myData',
        // value
        {'myKey': 'myValue'}
    ).on('success', function(data, response) {
        // this will be called when everything is done
        console.info('done saving the data');
    });
</script>

Obtaining your data from the cloud is very simple as well:

<script type="text/javascript">
    ws.get(
        // key
        'myData'
    ).on('success', function(data, response) {
        console.info(data);
    });
</script>

That's it, enjoy your experiments with CloudMine!

Post a Comment