问题描述
我正在尝试从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);
)};
1楼
stdob--
2
已采纳
2015-07-30 12:09:41
尝试这个:
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);
});