Can't add image downloaded from web using request and pipe
See original GitHub issueHi
I want to download a .jpg file from Web and add it to pdf, bug got Error: stream.push() after EOF
error.
Here is the code:
var out = fs.createWriteStream(filepath);
request('some-url.jpg').pipe(out);
out.on('finish', function(){
var stats = fs.statSync(filepath);
console.log(stats);
doc.addPage().image(filepath, 33, 34, {fit: [100, 100]});
});
Here is the error:
{ dev: 206529591,
mode: 33206,
nlink: 1,
uid: 0,
gid: 0,
rdev: 0,
blksize: undefined,
ino: 3377699720980692,
size: 132953,
blocks: undefined,
atime: Wed Mar 18 2015 16:28:03 GMT+0800 (中国标准时间),
mtime: Wed Mar 18 2015 17:14:18 GMT+0800 (中国标准时间),
ctime: Wed Mar 18 2015 17:14:18 GMT+0800 (中国标准时间),
birthtime: Wed Mar 18 2015 16:28:03 GMT+0800 (中国标准时间) }
data length: 132953
events.js:85
throw er; // Unhandled 'error' event
^
Error: stream.push() after EOF
at readableAddChunk (_stream_readable.js:149:15)
at PDFDocument.Readable.push (_stream_readable.js:126:10)
at PDFDocument._write (E:\2yi\ss4cn\node_modules\pdfkit\js\document.js:153:12)
at PDFReference.finalize (E:\2yi\ss4cn\node_modules\pdfkit\js\reference.js:73:21)
at PDFReference.finalize (E:\2yi\ss4cn\node_modules\pdfkit\js\reference.js:10:61)
at PDFReference.end (E:\2yi\ss4cn\node_modules\pdfkit\js\reference.js:66:21)
at JPEG.embed (E:\2yi\ss4cn\node_modules\pdfkit\js\image\jpeg.js:68:16)
at PDFDocument.module.exports.image (E:\2yi\ss4cn\node_modules\pdfkit\js\mixins\images.js:28:15)
at WriteStream.<anonymous> (E:\2yi\ss4cn\index.js:111:19)
at WriteStream.emit (events.js:129:20)
From the stats
, I think the file is well downloaded.
Node.js v0.12.0 on Wdinwos 7, and the pdfkit 0.7.0.
Thanks
Issue Analytics
- State:
- Created 9 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Downloading images with node.js [closed] - Stack Overflow
I'd suggest using the request module. Downloading a file is as simple as the following code: var fs = require('fs'), request = require('request');...
Read more >download an image with get request from web URL in python
In this tutorial u will learn1. how to download an image from url with get requests using python.2. downloading with get requests in ......
Read more >How To Web Scrape & Download Images With Python
Thanks to Smartroxy for sponsoring this video! Smartproxy provides the best proxies for data scraping and countless other use cases.
Read more >How to download images with NodeJS? - ScrapingAnt
This tutorial will show you how to download images and files with NodeJS. There are libraries that can help you achieve that, like...
Read more >Axios — Download Files & Images in Node.js - Future Studio
It has a convenient and modern API simplifying asynchronous HTTP request and response handling. Let's explore how to download files with ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone else that comes across this post like I did and didn’t know how to download an image to a buffer in memory here’s how I did it using axios:
not working for me