Book Image

Node.js Blueprints

By : Krasimir Stefanov Tsonev
Book Image

Node.js Blueprints

By: Krasimir Stefanov Tsonev

Overview of this book

Table of Contents (19 chapters)
Node.js Blueprints
About the Author
About the Reviewers

Uploading the images

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) {
  } else {
    var file = filesToOpen.shift();
    console.log("Uploading " + file.replace(/\//g, '\\').replace(process.cwd(), ''));
      method: 'upload',
      params:  { photo : file },
      accessToken : { 
        oauth_token: options.oauth_token,
        oauth_token_secret: options.oauth_token_secret
      next: function(data){

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: