Custom Formatters, path to url, filename from path, file extension from path, node & php

Three simple formatter extensions for managing paths in server connect for node and php

Each can be found in the "Custom File Actions" formatters group, in this case alongside an existing node extension, "Get domain from URL"

Path to URL )
this takes a file path and returns it's URL

So public/assets/myimage.jpg
returns /assets/myimage.jpg

Get Filename from Path
public/assets/myimage.jpg
returns myimage.jpg

Get File Extension from Path
public/assets/myimage.jpg
returns .jpg

I will be releasing PHP versions of the last two but a current Wappler bug prevents release at this time.

2 Likes

All now also available for php users, installable from project manager

2 Likes

I have an issue with this extension on node:
I have this:

So storing each image:

But this is the result:

But on each set value which has the same expression:

So I can't figure it out what is the issue here..

PS: Storing with the set value output does the job:

image

Any idea?

Are you using a local path or a full url?
Can i have an example of the image input
Should you not be manipulating the upload.path rather than the image name

I'm using the saveimage output which has a name newImage3
You can't see the name on the picture but it's the name of save image step:

When using a set value with {{newImage3.getfilename()}} I can see the name of the file


But inserting {{newImage3.getfilename()}} shows [objet Promise]
image

Records 3,4,5,9 and 10 where saved using the setvalue output, which has the exactly same expression

I don't know if it's related to your extension, but this it's a difficult one to analyse.. Both have the exact same expression

Franse, i need to see what the actual input is.
Can you give me an example of what newImage1,2 or 3 actually contains?
Maybe an example of one which works and one which generates an error

Here's an example of 2 images:

I don't really understand this question, and first of all, sorry if I'm not being clear:

I'm using a repeat of the upload files and for each item I'm doing 3 resizes.

This expression in a set value action {{newImage3.getfilename()}} returns the correct value:
image3filename : "fc6eed50-c608-4030-9bcf-16b28fbaf72b.png"

But in the insert step, this expression save this to the db: [object Promise]`

PS: Thanks and let me simplify the project so it can be more clear for reading

Here is a simple version:

You can see that the expression on the set value and the insert, is the same:

However:

The set value output:

The inserted value:

Here is the code:
Server side

{
  "meta": {
    "options": {
      "linkedFile": "/views/bugtest/simplefileupload.ejs",
      "linkedForm": "form1"
    },
    "$_POST": [
      {
        "type": "file",
        "fieldName": "input1",
        "name": "input1",
        "sub": [
          {
            "name": "name",
            "type": "text"
          },
          {
            "name": "type",
            "type": "text"
          },
          {
            "name": "size",
            "type": "number"
          },
          {
            "name": "error",
            "type": "text"
          }
        ],
        "outputType": "file"
      }
    ]
  },
  "exec": {
    "steps": [
      {
        "name": "upload",
        "module": "upload",
        "action": "upload",
        "options": {
          "fields": "{{$_POST.input1}}",
          "path": "/public/assets/bugtest/simpleimage",
          "template": "{guid}{ext}"
        },
        "meta": [
          {
            "name": "name",
            "type": "text"
          },
          {
            "name": "path",
            "type": "text"
          },
          {
            "name": "url",
            "type": "text"
          },
          {
            "name": "type",
            "type": "text"
          },
          {
            "name": "size",
            "type": "text"
          },
          {
            "name": "error",
            "type": "number"
          }
        ],
        "outputType": "file"
      },
      {
        "name": "image",
        "module": "image",
        "action": "load",
        "options": {
          "path": "{{upload.path}}"
        },
        "outputType": "object",
        "meta": [
          {
            "name": "width",
            "type": "number"
          },
          {
            "name": "height",
            "type": "number"
          }
        ]
      },
      {
        "name": "",
        "module": "image",
        "action": "resize",
        "options": {
          "instance": "image",
          "width": 65
        }
      },
      {
        "name": "newImage",
        "module": "image",
        "action": "save",
        "options": {
          "instance": "image",
          "path": "/public/assets/bugtest/simpleimage/resized"
        }
      },
      {
        "name": "setvalueoutput",
        "module": "core",
        "action": "setvalue",
        "options": {
          "value": "{{newImage.getfilename()}}"
        },
        "meta": [],
        "outputType": "text",
        "output": true
      },
      {
        "name": "insert",
        "module": "dbupdater",
        "action": "insert",
        "options": {
          "connection": "test_localhost",
          "sql": {
            "type": "insert",
            "values": [
              {
                "table": "test",
                "column": "value_test",
                "type": "text",
                "value": "{{newImage.getfilename()}}"
              }
            ],
            "table": "test",
            "returning": "id_test",
            "query": "insert into `test` (`value_test`) values (?)",
            "params": [
              {
                "name": ":P1",
                "type": "expression",
                "value": "{{newImage.getfilename()}}",
                "test": ""
              }
            ]
          }
        },
        "meta": [
          {
            "name": "identity",
            "type": "text"
          },
          {
            "name": "affected",
            "type": "number"
          }
        ]
      }
    ]
  },
  "usedModules": {
    "sharp": "^0.29.3"
  }
}

And client side

<form id="form1" is="dmx-serverconnect-form" method="post" action="/api/bugtest/insertimagebug">
    <div class="form-group mb-3">
        <input type="file" class="form-control" id="input1" name="input1" aria-describedby="input1_help">
        <button id="btn1" class="btn" type="submit">Button</button>
    </div>
</form>

So the problem is the async function on the extension js, assuming set value uses await..
Can we get rid of the async?
If so, how other expressions can result?

released update 1.0.5, can you check it.