gpt4 book ai didi

javascript - 类型错误 : undefined is not a function at pipe in nodejs

转载 作者:行者123 更新时间:2023-12-02 15:53:18 24 4
gpt4 key购买 nike

我正在尝试从 jira 服务器下载文件并将其存储在我的文件中,但我无法将其存储在我的文件中,并显示以下错误:

(data.body).pipe(fs.WriteStream('file.xlsx'));

^

TypeError: undefined is not a function

我的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);
)};

最佳答案

试试这个:

request({
method: "GET",
"rejectUnauthorized": false,
"url": url,
"headers" : {"Content-Type": "application/json",
"Authorization": "Basic"+' '+encodedCredentials}
}).pipe(
fs.createWriteStream('file.xlsx')
);

或者这个:

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);
});

关于javascript - 类型错误 : undefined is not a function at pipe in nodejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31723012/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com