question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'createObjectURL' of undefined at BlobStream.toBlobURL

See original GitHub issue

Unable 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:closed
  • Created 7 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
ahena001commented, May 13, 2016

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” and doc is piped as previously mentioned by @devongovett -

i.e. ,

router.get('routeURL', function(req,res,next){
  var doc = new PDFDocument();

  doc.image(someData.logo, 15, 15, {
      height: 100
  });

  doc.end();

  res.contentType("application/pdf");
  doc.pipe(res);  

}
1reaction
devongovettcommented, May 13, 2016

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')).

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot Read Property 'CreateObjectURL' Of ...
The problem here is that you are using aws-amplify-angular and you imported it somewhere in your modules.
Read more >
URL.createObjectURL() - Web APIs | MDN
The URL.createObjectURL() static method creates a string containing a URL representing the object given in the parameter.
Read more >
Blob - The Modern JavaScript Tutorial
createObjectURL is to convert a Blob into a base64-encoded string. That encoding represents binary data as a string of ultra-safe “readable” ...
Read more >
File API - W3C
A FileReader interface, which provides methods to read a File or a ... reading a chunk from blob , or failure if a...
Read more >
createObjectURL · WebPlatform Docs
The ObjectURLOptions object has one property, oneTimeOnly, that is set to false by default. To set the URL for the object (blob, stream,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found