Cannot read property 'createObjectURL' of undefined at BlobStream.toBlobURL
See original GitHub issueUnable to generate pdf. Getting this issue. `F:\nodejs\projects\media-template\node_modules\blob-stream\index.js:48 return URL.createObjectURL(this.toBlob(type)); ^
TypeError: Cannot read property ‘createObjectURL’ of undefined at BlobStream.toBlobURL (F:\nodejs\projects\media-template\node_modules\blob-stream\index.js:48:13) at BlobStream.<anonymous> (F:\nodejs\projects\media-template\routes\campaign.js:115:25) at emitNone (events.js:72:20) at BlobStream.emit (events.js:166:7) at finishMaybe (_stream_writable.js:468:14) at endWritable (_stream_writable.js:478:3) at BlobStream.Writable.end (_stream_writable.js:443:5) at PDFDocument.onend (_stream_readable.js:490:10) at PDFDocument.g (events.js:260:16) at emitNone (events.js:67:13) at PDFDocument.emit (events.js:166:7) at endReadableNT (_stream_readable.js:905:12) at doNTCallback2 (node.js:441:9) at process._tickCallback (node.js:355:17)`
I am using the following configuration.
`{ “name”: “media-template”, “version”: “0.0.0”, “private”: true, “scripts”: { “start”: “node ./bin/www” }, “dependencies”: { “body-parser”: “^1.13.3”, “cookie-parser”: “~1.3.5”, “debug”: “~2.2.0”, “config”:“", “ejs”: "”, “express”: “~4.13.1”, “express-session”: “^1.10.1”, “express-validator”: “2.18.0”, “fs”: “0.0.2”, “pdfkit”:““, “blob-stream”:””, “pdfkit”:“", “mongoose”: "”, “morgan”: “~1.6.1”, “multer”: “^1.1.0”, “passport”: “^0.2.1”, “passport-local”: “^1.0.0”, “passport-local-mongoose”: “^1.0.0”, “serve-favicon”: “~2.3.0” } }
`
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (1 by maintainers)
Top GitHub Comments
Adding to the server side functionality and working around blob-stream, as @devongovett says, pipe instead.
In my case I needed to serve the PDF to the client ( server -> client browser ).
For me, what worked was piping the doc directly to the response back to client. Since the PDF is to be rendered on the browser, the
res.contentType
is set to “application/pdf” anddoc
is piped as previously mentioned by @devongovett -i.e. ,
blob-stream can only be used in the browser, not node.js. You need to pipe to a file instead, e.g.
doc.pipe(fs.createWriteStream('out.pdf'))
.