[英]TypeError: undefined is not a function at pipe in nodejs
I am trying to download a file from jira server and storing in my file but i am not able to store it in my file saying below error: 我正在尝试从jira服务器下载文件并存储在我的文件中,但是我无法将其存储在我的文件中,提示以下错误:
(data.body).pipe(fs.WriteStream('file.xlsx'));
^
TypeError: undefined is not a function
my nodejs code: 我的nodejs代码:
var express = require('express');
var app = express();
var request = require('request');
var bodyParser = require("body-parser");
var fs = require('fs');
var https = require('https');
app.use(bodyParser.urlencoded({ extended: false }));
require('ssl-root-cas/latest').inject();
var credentials = 'user:pass';
var encodedCredentials = new Buffer(credentials).toString('base64')
var url = ' https://gec-jira01.example.com/secure/attachment/IWREQ-373_update.xlsx';
request({
"method": "GET",
"rejectUnauthorized": false,
"url": url,
"headers" : {"Content-Type": "application/json",
"Authorization": "Basic"+' '+encodedCredentials}
}, function(err, data, body) {
//console.log(data);
(data.body).pipe(fs.WriteStream('file.xlsx'));
console.log(data.body);
)};
Try this: 尝试这个:
request({
method: "GET",
"rejectUnauthorized": false,
"url": url,
"headers" : {"Content-Type": "application/json",
"Authorization": "Basic"+' '+encodedCredentials}
}).pipe(
fs.createWriteStream('file.xlsx')
);
or this: 或这个:
request({
method: "GET",
"rejectUnauthorized": false,
"url": url,
"headers" : {"Content-Type": "application/json",
"Authorization": "Basic"+' '+encodedCredentials}
},function(err,data,body) {
fs.WriteStream('file.xlsx').write(body);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.