Get upload progress for Google Drive NodeJS client?

前端 未结 2 1768
时光取名叫无心
时光取名叫无心 2021-01-06 11:42

After we get the request object from req = drive.files.insert how to use it find file upload progress ?

I searched for it in the req string

2条回答
  •  生来不讨喜
    2021-01-06 12:27

    Here's how it's done

    function uploadFile(){
        var path = untildify("~/workspace/a.jpg");
        var drive = google.drive('v2');
        console.log('start upload');
        var req = drive.files.insert({
            resource: {
                title: "a.jpg"
            },
            media: {
                body: fs.createReadStream(path)
            },
            auth: oauth2Client
        }, function(err, response, body) {
            if (err) {
                console.log(err);
            } else {
                console.log('finish upload');
                clearInterval(q);
            }
        });
        var q = setInterval(function () {
             console.log("Uploaded: " + req.req.connection.bytesWritten);
         }, 250);
    }
    

    Reference : Node.js progress indicator feedback - Answer by Riel

    And special thanks to Ryan Seys for helping me out.

提交回复
热议问题