嘿,我找到了这个v2解决方案来获取文件的上传进度。 Get upload progress for Google Drive NodeJS client?
这是我的代码
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
结果。任何想法为什么?
答案 0 :(得分:0)
我认为上面的代码是错误的: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() {
父级:[folderID]为folderID,您需要从google drive api的默认脚本中执行列表视图。