Start a new topic

New to node.js - need bootstrap to downloadfiles from Kinvey

Kinvey users,



I have an app (MotorCardiogram) that is creating data and uploading it to Kinvey. Now I want to download it to my machine and process it. In looking at the toolsets available for kinvey, node.js looks like it will fit the bill (intermediate location - on my laptop or linux based computer, small, easy to run). What I want to do is periodically pull all of the files loaded onto the kinvey servers to my machine, and then delete them from the server after I pull them down.



I would like to use implicit users for the time being, but even if I need to create a user on the console, and then use that user in my script, I'm fine with that.



Perhaps I'm just not "getting" node.js and javascript, but if someone could post a complete example instead of the breadcrumbs that kinvey has published, I would really appreciate it.



Thanks,



Soren - MotorCardiogram.
1 Comment

Hi Soren,



The "breadcrumbs" are pretty complete. For node.js you'll need to do something like this:



promise.then(function() {

Kinvey.User.login('user', 'password', {

success: function(response) {

var promise = Kinvey.File.download(fileId, {

success: function(response) {

console.log('file downloaded');

},

error: function(e) {

console.log('ERROR: downloading failed: ' + e.description);

}

});

},

error: function(e) {

console.log('ERROR: User not found: ' + e.description);

}

});

});



You need to download every file by file id. The download happens in two steps, 1. it gets file meta data from kinvey then 2. it downloads the file from google. Sometimes, kinvey will have meta data on a file but no file. The node library won't really throw the right error in this case. For what you want to do, I'd use the REST api (and probably not node if you're new to it.) You download files in two steps explicitly, and you can just collect all the meta data in one go and simply loop through and grab all the files. Also, if you use master secret you won't need to create any users to download the files (I think you might need to create one to delete them.)
Login or Signup to post a comment