Save base64 encoded image to file in Bootstrap using FS Node.js modules

hi everyone, can someone please help me with this. I've got base64 encoded image that should be saved to a file when it's clicked on. This image is not a link but raw data saved as the src for the image dynamically. Checking the forums, it seems like the following code would work. However, its using Node.js modules. How do I make this code work? How can I import the FS module into bootstrap to make this code? var fs = require("fs"); var strippedPhotoUri = imageData.substring("data:image/jpeg;base64,".length); var buf = new Buffer(strippedPhotoUri, "base64"); fs.writeFileSync(filename, buf, "base64", function(err) { if (err) { console.error("error: " + err); } }); can someone help with making this code work in Bootstrap please.

Thank you for starting this thread! Bootstrap Studio is a frontend tool and doesn't support importing Node.js modules. You can only write frontend js code that can run in your browser. If a library is present on Cloudflare or another CDN, you can link from the Design panel (in the right sidebar). Your sample code depends on the fs module which is only present in Node.js and won't work outside of it.

The problem I'm in is that I'm building all my source from a db, not the server. So there's no URL link to the files for the H5 download option. I query the image, video or document from the db and display it as an image for download. So when the end user clicks on the image, it needs to write the raw data to a file on the users' local machine. I found a thread that works for text files that is built up, but can't figure out why it doesnt work for the image file. Text working excerpt below:

<script> function download(filename, text) { var element = document.createElement('a'); element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); element.setAttribute('download', filename); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element); } // Start file download. download("hello.txt","This is the content of my file :)"); </script>

The above works for text. But when I call it with the base64 encoded data (changing the text/plain attribute), nothing happens. Any ideas?