In the previous to last post we created a series of files, each one with data from a recorded session. We want to upload that data into a server for further processing.

In this post we will add the upload mechanism and we will build a simple web server that will receive the data.

From this post one we will only show the code for the implementation and left the test code out of the posts unless there is something specially interesting on it.
You can always get the code with all the tests in the github repository for this project.

Getting the saved files

Before uploading any of the files we need to get a list of files available for upload.
We use the cordova file plugin that we already added previously to the project.
We will add a list method to our fileService

We expose a public list function and we move the implementation into a private function.

The server

We need to upload the files to a server, for this exercise we created a simple web server using Express and we deploy it to Heroku. I'm not implementing any type of authentication or security at this point. We will do that later.

The code for the web server can be found on Github You can clone and use it as a starting point if you wish.

And the server service

We start by installing the cordova file-transfer plug-in.

cordova plugin add org.apache.cordova.file-transfer

Once the plug-in is installed we can write our upload method. We want to pass an array of FileEntry objects and send each one to the server.

We also want to report back success or error for each entry individually what makes our implementation very simple.