node.js - Bad Request: SendStream.error while sending file as response -


i using express node.

i attempting send pdf file response.

this pdf file first retrieved server using http.request() after wish pipe response.

that is, when browser makes request route '/pdf, carry out following:

app.get('/pdf', function (req, res) { var options = { host: host, path: path, method: 'get', headers: {} };

var requesting = http.request(options, function (response) {     var body = '';      response.setencoding('utf8');      response.on('data', function (chunk) {         body += chunk;     });     response.on('end', function () {         var data = null;         if (body) {             try {                 data = json.parse(body);             }             catch (err) {                 data = body;             }         }          res.sendfile(data);     }); });  requesting.end(); 

});

however, error thrown @ res.sendfile(data):

error: bad request     @ sendstream.error (redacted/send.js:145:16)     @ sendstream.pipe (redacted/send.js:298:31)     @ serverresponse.res.sendfile (redacted/response.js:339:8)     @ incomingmessage.<anonymous> (redacted/api.js:289:17)     @ incomingmessage.eventemitter.emit (events.js:117:20)     @ _stream_readable.js:920:16     @ process._tickcallback (node.js:415:13) 

how pass http request body (with content type 'application/pdf') browser?


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -