How to decode a base64 image to a file server side

I found information about client-side decoding but nothing that explains how to decode a base64 image to a file server-side?

Hi ben, I am working with an API that takes and image and removes the background. It returns result at a base64 encoded image. I need to convert it to a file. right now all it returns is the huge encoded string where my image is supposed to be.

Sorry, misread the question. Rereading it looks like you want to decode the image to a file.

May I ask what the reason is?

I think I may have answered that while you were revising yours, did you see it?

1 Like

One way would be to use NodeJS as per https://stackabuse.com/encoding-and-decoding-base64-strings-in-node-js/

Have a look at this answer
https://stackoverflow.com/questions/6926016/nodejs-saving-a-base64-encoded-image-to-disk
and this package
https://www.npmjs.com/package/js-base64

I am thinking that node-js would be the way to go. I found an option with php using the fopen, write, and fclose functions, I’m pretty much learning how to do everything from scratch so it takes me a while to figure it out.

Ill look at those other options too.

thnx.

If PHP is your preferred server model, then I would stay with the PHP solution. Personally I am wrapped in using NodeJS.

Hi.


Take a look at this image to base64 custom module I created. You can probably use some library like this for your requirement to create image from base64.

I am so new at this that I have been thinking about switching to nodeJS. Do you think the learn curve is higher with node?

I started answering your question, but ran into a jumbled mind frame. There are so many aspects of NodeJS. Where PHP is a pure framework tool for web development, NodeJS can be used for projects that do not involve a browser.

So, the short answer to your question: IMHO, start using NodeJS, it is really simple thanks to Wappler.

1 Like

@sid thank you for the information. I have been doing some research and it seems like the fs module has many features that might make a nice custom module. I started trying to create a custom module in Wappler and soon got overwhelmed. My initial issue came with the stage of creating the ui and the .hjson file. how do I find the information needed to complete it correctly?

Would you be willing to coach me through the process? Here is the module link https://nodejs.dev/learn/the-nodejs-fs-module

Looks like its quite a simple function built-into NodeJS fs package, like you have discovered.
Please take a look at the code here: https://stackoverflow.com/a/6933413

I think the link I shared earlier should be enough for creating your custom module. Please try to go through it once more.

Feel free to start here

will do, thx