Problem when requesting a file (image / pdf / excel sheet) from the server, and then to the handset before res

Scenario:

I need to send a user file that is remotely stored on a server (cloud) in a browser. I can request an image from the server and then transfer it to the browser, but it does not work for other files like pdf, excel sheet, etc.

exports.fetchFile = function(req, res, next){ var fileUrl = "/" + req.params.fileUrl; console.log(fileUrl); async.auto({ 'A': function(callback) { var queryObj = { 'myUrl' : fileUrl}; // DB Query to retrieve user file information like url, type, etc. UserFileCtrl.fetchUserFile(queryObj, callback); } }, function(err, results){ if(err) { return res.send(500, "error"); } var secureUrl = results['A']['secureUrl']; var fileType = results['A']['fileType']; // this will be "application/pdf" for pdf res.setHeader('Content-Type', fileType); request(secureUrl).pipe(res); }); } 

The above code gives an empty PDF file for the client, whereas if I open the cloud URL directly, then it fits correctly. I rack my brains for a long time, but I can’t get any of this.

I really appreciate your help.

Edit: I also found this similar question: The express server sends an empty PDF file , but this also does not work for me. I tried disabling connnect-livereload, but even then it does not work.

The problem occurs only for PDF files. All other formats work fine.

0
express request cloudinary
source share

No one has answered this question yet.

See similar questions:

eleven
Express - returns binary data from a remote webservice
5
Express server sends an empty PDF file

or similar:

256
Download file from NodeJS server using Express
2
Why is the Node fs.writeFile () method a successful but empty browser sent to the browser?
one
NodeJS sendFile returns an empty file from the server
one
Invalid request: SendStream.error when sending a file as a response
0
Send PDF in express route mode and force the browser to download
0
node.js + express API 200 status code, but client is still waiting
0
"Unable to get / db / read / getall" to access node.js API using nginx reverse proxy on a bit of digitalocean
0
CloudMan File-Upload / ReactJs / Express No Response Unable
-one
JS client host versus server

All Articles