Loading pdfs from a remote server via a stream
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2.2k
- Forks
- 394
- Avg merge
- 3d 5h
- Merged PRs (30d)
- 7
Description
I'm trying to load a single PDF from a remote server. Here is my approach:
(I can confirm that if I just pipe the request into a write stream it saves the PDF fine)
var request = require('request');
var pdfParser = require('pdf2json');
var pdfUrl = 'somepdf.pdf'
var pdfPipe = request({url: pdfUrl, encoding:null}).pipe(pdfParser);
pdfPipe.on("pdfParser_dataError", err => console.error(err) );
pdfPipe.on("pdfParser_dataReady", pdf => {
//let pdf = pdfParser.getMergedTextBlocksIfNeeded();
console.log(pdfParser.getAllFieldsTypes());
});
However, I'm getting an error:
stream.js:45
dest.on('drain', ondrain);
^
TypeError: dest.on is not a function
at Request.Stream.pipe (stream.js:45:8)
at Request.pipe (/Users/zaf/development/minerva-bot/node_modules/request/request.js:1395:34)
at Object.<anonymous> (/Users/zaf/development/minerva-bot/plugins/exam_module/index.js:9:53)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:117:18)
at node.js:951:3
Code constructed from here: http://stackoverflow.com/a/36882510/3779915
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at plugins/exam_module/index.js:9 and trace the Request.pipe call shown in the stack through stream.js:45 and request/request.js:1395. Reproduce the remote PDF stream case and inspect whether pdfParser is a valid destination; done means the request no longer raises the reported TypeError and the parser emits its documented data event.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100