本文介绍了获取Google Drive NodeJS客户端的上传进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从 req = drive.files.insert
获取请求对象后,如何使用它来查找文件上传进度?
我通过多次调用 req字符串
来搜索它,但无济于事。
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);
解决方案
p>
function uploadFile(){
var path = untildify(〜/ workspace / a.jpg);
var drive = google.drive('v2');
console.log('start upload');
var req = drive.files.insert({
资源:{
标题:a.jpg
},
媒体:{
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);
参考: - 通过回答Riel
特别感谢 Ryan Seys 为了帮助我。
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
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);
}
解决方案
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.
这篇关于获取Google Drive NodeJS客户端的上传进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!