Skip to content

Issue downloading pdf; file is corrupted #2063

@varunj90

Description

@varunj90

Hi,

I am receiving a pdf file from the server on the internet. This is in binary format and as soon as I try adding it in a callback, the file gets corrupted/damaged. Whereas if I simply return the file without a cb, it gets downloaded.

_var options = {
url: config.baseURL + config.getDocument.url + docId,
encoding: null,
method: 'GET',
qs: {'a': true, 'alf_ticket': ticket}
};

// send out request
request(options, function(error, response, body) {onGetDocumentResponse(error, response, body, callback);});
}
_

In my remote method when I do the following

_ params.res.setHeader('Content-Type', 'application/pdf');
params.res.setHeader('Content-Disposition', 'attachment; filename=' + params.docid + '.pdf');

  return params.res.end(result.body);_

It downloads the file perfectly, but as soon I introduce callback

_cb(null,result.body);
_
The pdf received is damaged (size is 195 bytes vs 4kb of original file)

I've read on multiple threads of having issues in downloading pdfs in node. Is there any solution that you could recommend which would allow us to use a callback instead of a return statement (since that would intercept all middleware)

@raymondfeng
@richardpringle

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions