Need Help Converting Base64 to a PNG/SVG Via Plugin

Hello Everyone:

I’m working on a free/open-source plugin that will generate barcodes. I’m using the Node.js library jsbarcode which also uses the library canvas. I have written the code to produce a barcode as a base64 string. The code is below:

function(properties, context) {
	const JsBarcode = require('jsbarcode');
	const { Canvas } = require("canvas");

	const canvas = new Canvas();
	JsBarcode(canvas, "Hello");

	let base64String = canvas.toDataURL();

	let base64Image = base64String.split(';base64,').pop();

	const fs = require('fs');

	fs.writeFile('image.png', base64Image, {encoding: 'base64'}, function(err) {
    	console.log('File created');
	});
    
    return {
        barcode: "" //need a URL to return ("barcode: String (image URL)")
	}
}

The only thing I can’t figure out is how to generate and save a file. I’ve poked around and know it starts with the base64 encoding, which I have above, or file system, which I have too. Any help is greatly appreciated and is going to a free plugin for the community! Thanks!

I did it! https://bubble.io/plugin/barcode-generator-1609209698393x206083649188921340

Use my code for an example of email me for help!

1 Like

I have a problem in similar thing. Please provide your email or email me at entrepreneurtanmay@gmail.com

@entrepreneurtanmay I emailed you a basic walkthrough, and wrote a long-form guide in the forum here: [Guide] How to Upload Files to the File Manager from Plugin Actions

Thanks, Nicholas for such a detailed guide.

I love the bubble community here…

1 Like