Convert a base64 encoded image to the original image

Hi all,

Is it possible to convert a base64 encoded image to the original image file using codeless and store the resulting file in a backendless folder ? If yes, How ?

Thank’s in advance.

Hi Thierno,

Welcome to the wonderful world where Codeless meets code. Here’s what you can do to add this functionality:

  1. Click Business Logic In the BACKEND section of console and switch to the CODING tab.
  2. Make sure JS is selected in the drop down, right click the services node in the tree:
  3. Select New File and enter Base64Service.js. Click CREATE
  4. Paste the following code in the editor:
 class Base64Service
 {
   /**
   * @param {String} data
   * @returns {Promise.<String>}
   */ 
  toBase64( data ) {
    return Buffer.from( data ).toString('base64')
  }

    /**
   * @param {String} data
   * @returns {Promise.<String>}
   */ 
  fromBase64( data ) {
    return Buffer.from( data, 'base64' ).toString()
   } 
 }
 Backendless.ServerCode.addService( Base64Service );
  1. Click the button to deploy the service:
    image
  2. Once deployed, switch to the API SERVICES tab and try it out by entering some text into the data field and clicking INVOKE:
  3. Now that the service is there and is working, you can start using it in Codeless:

Hope this helps.

Mark

1 Like

Great ! it works fine after some adaptation.

Thanks a lot @mark-piller :slightly_smiling_face: