将文件从请求管道上传到google drive API时出现401错误

时间:2016-03-24 10:49:35

标签: javascript node.js google-api request

我正在将文件从网络上传到谷歌驱动器,这里我使用nodejs请求模块并将其管道到谷歌驱动器api,它工作时我不在驱动器和请求模块之间添加任何其他。 我也使用进度流来模块获取统计信息,但每当我管道进度流时它会抛出401错误。

 .on('response', response => {
                //On Response we create headers and upload the file
                options.headers = response.headers;
                options.headers["Authorization"] = "Bearer " + req.cookies.access_token.access_token;
                if (response.statusCode == 200) {
                    var metaData = response.headers;
                    metaData.name = path.basename(req.query.url);
                    metaData.size = prettysize(response.headers['content-length'], true, true);
                    metaData.hash = crypto.createHmac('sha256', 'samundrakc').update(response.headers.name + Date.now()).digest('hex');
                    fileId = response.headers.hash;
                    res.json(req.success(metaData));
                    progress.setLength(response.headers['content-length']);
                }
                else {
                    return res.json(req.error("This Url doesn't provide direct download"));
                }
                options.headers = _.omit(options.headers, 'hash', 'name', 'size');
                console.log(options)
            })
            .pipe(progress)
            .pipe(request.post(options, (err, status, result)=> {
                // console.log(err,status,result)
                console.log(options)
                console.log(result) 

0 个答案:

没有答案