Deliver database image column "bytea"

Hello everyone,

I am new to the Wappler world (I really want it in my life), my first mission, to migrate a legacy system to wappler, in this legacy system, I have a table (BD) with a “logo” column with type “bytea”, then in the system legacy (NodeJS) I can receive in the API the bytes of the image and store it in the BD column, another URI of the API retrieves the bytes of the BD, applies the content-type and responds with the logo, so basically I have this scenario:

Logo upload:
POST: http://{endpoint}/institutions/e605d637-8eb6-479b-8dcf-bbcabd26f8eb

Get Logo:
GET: http://{endpoint}/institutions/e605d637-8eb6-479b-8dcf-bbcabd26f8eb

I have already observed some discussions about the bad practice of saving images in the database here on the forum, but it is a legacy system that I cannot change at this moment, I would like to know if there is any possibility of doing this in wappler.

Thank you all!


Welcome to the community.
As you have correctly read, storing images is not a good approach.
With the latest releases, you now have the power of custom modules and formatters.
Since this looks like a NodeJS app, you can use it to convert the bytea type data to an image and return that in response.

You can get started here: PREVIEW: Wappler Extensibility - Writing Custom Modules and Formatters for Server Connect

Hello sid,
Thank you for your help!

Something minimalist:

  type: 'imageToBytes',
  module : 'imageToBytes',
  action : 'getBytes',
  groupTitle : 'My Modules',
  groupIcon : 'fas fa-lg fa-project-diagram comp-images',
  title : 'Image to Bytes',
  icon : 'fas fa-lg fa-file-alt comp-images',
  dataPickObject: true,
  dataScheme: [
      { name: 'bytes', type: 'text' }
  properties : [
      group: 'Source Image',
      variables: [
        { name: 'file', optionName: 'file', title: 'File', type: 'file', required: true, defaultValue: '', serverDataBindings: true},
        { name: 'output', optionName: 'output', title: 'Output', type: 'boolean', defaultValue: false }

// JavaScript Document
module.exports = {
    getBytes: async function (optios) {
          const myText = 'MY_SAMPLE_TEXT';
          return myText;

The getBytes function is returning a text, my question is: Shouldn’t that text be accessible for the next “step”?

Thank you very much!

The dataScheme definition in this hjson does exactly that.
But you have to make sure you return a value with the key bytes in the main js file where the logic is.