这是我的代码,用于从提到的pdf
中获取uri
:
app.route("/downloadpdf").get(function(req,res){
var requestParameter = {
uri: "http://www.nitdgp.ac.in/career17/Revised%20advertisement%20for%20faculty.pdf",
method: "GET",
headers : {
'content-type' : 'application/pdf'
}
}
console.log(requestParameter.uri);
request(requestParameter, function(error, response, body) {
var buf = Buffer.from(body,'base64');
res.type('pdf').send(buf);
});
})
答案 0 :(得分:0)
您可以在请求中将编码设置为 null ,以确保下载二进制内容:
app.route("/downloadpdf").get(function(req,res){
var requestParameter = {
uri: "http://www.nitdgp.ac.in/career17/Revised%20advertisement%20for%20faculty.pdf",
method: "GET",
headers : {
'content-type' : 'application/pdf'
},
encoding: null
}
// The body will be a Buffer object
request(requestParameter, function(error, response, body) {
res.type('pdf').send(body);
});
})
从“请求”文档中: