获取 Google Drive NodeJS 客户端的上传进度? [英] Get upload progress for Google Drive NodeJS client?
本文介绍了获取 Google Drive NodeJS 客户端的上传进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们从req = drive.files.insert
得到请求对象后如何使用它来查找文件上传进度?
After we get the request object from req = drive.files.insert
how to use it find file upload progress ?
我在 req string
中搜索了它,多次调用它,但无济于事.
I searched for it in the req string
by calling it multiple times but to no avail.
function uploadFile(){
var path = untildify("~/workspace/incomplete/aw.jpg");
var drive = google.drive('v2');
var req = drive.files.insert({
resource: {
title: 'aw.jpg'
},
media: {
body: fs.createReadStream(path)
},
auth: oauth2Client
}, function(err, response) {
if (err)
console.log(err);
// else
// console.log(response);
});
console.log(req);
}
推荐答案
这是怎么做的
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);
}
参考:Node.js 进度指示器反馈 - Riel 回答
Reference : Node.js progress indicator feedback - Answer by Riel
特别感谢 Ryan Seys 帮助我.
这篇关于获取 Google Drive NodeJS 客户端的上传进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文