0

I'm using the drive node library to upload files from my node.js app using readstreams. Here's the snippet of the code. I want to write some logic once my app gets the callback that the upload is complete. How do I find out when the upload is complete or failed? The callback to the drive.files.create doesn't seem to be right place. Does createReadStream gives me a callback?

var fileMetadata = {
    name: "test.mp4",
    parents: [folder_id]
};

var media = {
    mimeType: mime_type,
    body: fs.createReadStream(fileid) 
};

drive.files.create({
    resource: fileMetadata,
    media: media
}, function(err, file) {
    //continue processing after upload is complete  
});
Kara
  • 6,115
  • 16
  • 50
  • 57
Sai
  • 3
  • 1

1 Answers1

1

The function fs.createReadStream() will just allow you to open up a readable stream in a very simple manner.

For your concern regarding the progress of upload API, you can just create a function like this to check the progress of your upload:

 var req = drive.files.create({
            resource: fileMetadata,
            media: media
        }, function(err, file) {
            //continue processing after upload is complete  
           clearInterval(q);
        });
  var q = setInterval(function () {
         // will check the upload progress from the request
         console.log("Uploaded: " + req.req.connection.bytesWritten);
         }, 250);

For more info:

Jessica Rodriguez
  • 2,899
  • 1
  • 12
  • 27