Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
FabricJS - Save data uri as image and as fabricjs json in nodejs backend

I am using nodejs to process a data uri such as data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA+gAA... on my backend and save it as image and also as fabricjs json.

var fs = require('fs'),
  fabric = require('fabric').fabric,
  out = fs.createWriteStream(__dirname + '/test_img/helloworld.png');

function main() {

  console.log("Test")
  let rawdata = fs.readFileSync('_test-scripts/img-data.txt', 'utf8');

  // save image
  let img = fabric.Image.fromURL(rawdata);

  var stream = img.createPNGStream();
  stream.on('data', function(chunk) {
    out.write(chunk);
  });

}

main();

I am using the following dependancies:

  "dependencies": {
    "fabric": "^5.2.1"
  }

When I run the above code I get:

Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'createPNGStream')
    at main (/workspaces/fabricjs_load_save.js:24:22)
    at <anonymous> (/workspaces/fabricjs_load_save.js:48:1)
    at Module._compile (internal/modules/cjs/loader:1103:14)
    at Module._extensions..js (internal/modules/cjs/loader:1157:10)
    at Module.load (internal/modules/cjs/loader:981:32)
    at Module._load (internal/modules/cjs/loader:822:12)
    at executeUserEntryPoint (internal/modules/run_main:77:12)
    at <anonymous> (internal/main/run_main_module:17:47)

The reason is that my img-variable is undefined.

Any suggestion what I am doing wrong?

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!