I am trying to load a pdf
in a new browser tab by passing it by res.send
so that the file remains private and not accessible unless the user has the necessary permissions.
The problem is that when the file pdf
is opened in the browser, the content does not appear, the sheets appear blank.
The code in node.js is:
FilesController.prototype.showPdfInBrowser = function (req, res) {
var filePath = "My url"
fs.readFile(filePath , function (err,data){
res.send(data);
});
};
And Angular's:
$scope.showPdfInBrowser = function (log) {
$http.get(log.url)
.then(function (data) {
console.log(data);
var file = new Blob([data.data], {type: 'application/pdf'});
var fileUrl = URL.createObjectURL(file);
window.open(fileUrl);
})
};