Google Drive API v3 请求进度错误

Google Drive API v3 Request progress bug

嘿,我找到了这个 v2 解决方案来获取文件的上传进度。

这是我的代码

function real_upload_files(auth) {
var drive = google.drive({ version: 'v3', auth: auth });

    fs.readFile('./test.zip', function(err, content){
        var fileMetadata = {
            'name': 'test.zip',
        };
        var media = {
            mimeType: 'application/zip',
            body: new Buffer(content, 'binary'),
        };
        var req = drive.files.create({
            resource: fileMetadata,
            media: media,
            auth: auth,
            fields: 'id',
        }, function(err, file) {
            if (err) {
                console.log(err);
            } else {
                console.log('File Id: ', file.id);
                clearInterval(q);  
            } 
        }); 

        var q = setInterval(function () {
         console.log("Uploaded: " + req.req.connection.bytesWritten);
        }, 250);

    }); 
} 

但我只得到

已上传:428
已上传: 428
已上传: 428
已上传:428

作为结果。知道为什么吗?

我认为上面的代码是错误的:D 然而,这最终对我有用 windows cmd。

function uploadFile_googledrive(auth) {
var drive = google.drive({ version: 'v3', auth: auth });


        var fileMetadata = {
            'name': 'box.box',
            parents: [ folderID ]

        };
        var media = {
            mimeType: 'application/octet-stream',
            body: fs.createReadStream('C:\Exports\box.box')
        };
        var req = drive.files.create({
            resource: fileMetadata,
            media: media,
            auth: auth,
            fields: 'id',
        }, function(err, file) {
            if (err) {
                console.log('Error while uploading your Container to Google Drive - Error: ', err);
            } else {
                console.log('Successfull uploaded your Container to Google Drive with ID: ', file.id);
                clearInterval(q);
            } // else
        }); // drive.files.create({


    var q = setInterval(function () {
         console.log("Uploaded: " + req.req.connection.bytesWritten);
     }, 1000);


} // function uploadFile_googledrive() {

parents:[folderID] 对于 folderID,您需要从 google 驱动器 api.

的默认脚本中执行列表视图