The last function that we will write is the uploadPhotos
method for the Flickr.js
module. It will use the global filesToOpen
array and upload the files one by one. Since the operation is asynchronous, we will continuously execute the function till the array is empty. We can see the code for this as follows:
var uploadPhotos = function() { if(filesToOpen.length === 0) { done(); } else { var file = filesToOpen.shift(); console.log("Uploading " + file.replace(/\//g, '\\').replace(process.cwd(), '')); flapiClient.api({ method: 'upload', params: { photo : file }, accessToken : { oauth_token: options.oauth_token, oauth_token_secret: options.oauth_token_secret }, next: function(data){ uploadPhotos(); } }); } }
The done
callback returns the application flow to index.js
, where the script is terminated. The result of the entire process will look like the following screenshot: