本文介绍了如何使用NodeJS下载pdf并将其发送给客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用NodeJS下载PDF文件,然后将其数据发送到客户端以嵌入到页面中。以下是我如何下载PDF文件:
exports.sendPdf = function(req,responce){
var donneRecu = req.body;
var url ='http://www.ieee.org/documents/ieeecopyrightform.pdf'//pdf link
http.get(url,function(res){
var data = '';
res.on('data',function(chunk){
console.log('downloads');
data + = chunk;
});
res.on(end,function(){
console.log('downloaded');
responce.header(Access-Control-Allow-Origin,*) ;
responce.header(Access-Control-Allow-Headers,X-Requested-With);
responce.header(200,{'content-type':'application / pdf' } $;
responce.send(data);
});
})on(error,function(){
callback(null);
});
}
如何将从NodeJS收到的数据发送到客户端?
编辑
i找到解决方案:
我的角度控制器中的下一个: p>
解决方案
解决方案:
我的角度控制器中的下一个: p>
I am trying to download a PDF file using NodeJS then send its data to client to be embedded in the page. Here is how I download the PDF file:
exports.sendPdf = function(req, responce) {
var donneRecu = req.body;
var url = 'http://www.ieee.org/documents/ieeecopyrightform.pdf'//pdf link
http.get(url, function(res) {
var data = '';
res.on('data', function(chunk) {
console.log('downloading');
data += chunk;
});
res.on("end", function() {
console.log('downloaded');
responce.header("Access-Control-Allow-Origin", "*");
responce.header("Access-Control-Allow-Headers", "X-Requested-With");
responce.header(200, {'content-type' : 'application/pdf'});
responce.send(data);
});
}).on("error", function() {
callback(null);
});
}
How do I send the data received from NodeJS to the client side?
EDITi found the solution :
next in my angular controller:
解决方案
i found the solution :
next in my angular controller:
这篇关于如何使用NodeJS下载pdf并将其发送给客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!