An update on the output issue.
I added a “name” parameter and I started seeing the output from my module.
Specifically, optionName: 'name'. With any value other than name, the output disappears again.
The UI still shows my dataScheme variable path as the output data item. But, the name img64 is what appears in the response. This is confusing.
What I was expecting is something like img64.path to have the data. Also, does this mean a property variable with optionName: 'name' is compulsory if I need to access an output from the custom module?
One last clarification remains for now - for the string output.
Giving this a bit of a though, I realize that if the output is a direct string, it would be available as a variable, and not via some nested param like img64.path… similar to how set value works. If the value set is an object, we can expect {{var1.key1}}, but if its a simple text, {{var1}} is used.
I think this wraps up my custom image to base64 module for NodeJS while giving a brief understanding of how it works. Plan to make a new post in detail tomorrow.
Hope to delve into more complex stuff soon. This is really really cool.
Wappler: A super powerful and extensible tool, with easy custom UI components - unheard of.
@George - On an existing NodeJS (Docker) project, I cannot get the extensions folder to appear, and I’m not sure if just manually creating it would work? I’ve tried opening targets and re-saving as in another post - but no luck.
I have a module, it is working great except that I am returning a value before a file write is finished.
The module is this:
exports.write_binary = function (options) {
//for converting file paths provided in UI
const { toSystemPath } = require('../../../lib/core/path');
//uuid package
const { v4: uuidv4 } = require('uuid');
//required for retrieving and saving file
const http = require('https');
const fs = require('fs');
//convert the user local_path provided in the API action to useable in the module
let path = toSystemPath(this.parseRequired(this.parse(options.local_path), 'string', 'fs.exists: path is required.'));
//evaluate the data binding for remoteURL
let remoteURL = this.parseRequired(options.file_url, 'string', 'parameter value is required.');
//generate uuid
let uuid = uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
//set the filename
let file_name = path + '/' + uuid;
//open up the stream for writing the file
const file = fs.createWriteStream(file_name);
async function fetchURL() {
await http.get(remoteURL, async function (response) {
response.pipe(file);
await new Promise((r, j) => {
file.on('close', r);
});
})
.on('error', function (err) { // Handle errors
fs.unlink(file_name); // Delete the file async. (But we don't check the result)
});
}
fetchURL();
return { "file_path": uuid };
};
I am attempting to retrieve a file from a URL and return the file name (currently a uuid) for use within standard Wappler actions.
I thought my async function fetchURL would block the return from happening until it was finished, but I'm clearly doing something wrong.
@patrick Based on the above, my code works well for me on a custom remote target, but I'm getting invalid results when used on remote docker.
For example I get this error:
{
"status": "500",
"code": "ENOENT",
"message": "ENOENT: no such file or directory, stat '/opt/node_app/public/avatars//public/avatars/94459807-a717-46d1-9407-3478871c2685'",
"stack": "Error: ENOENT: no such file or directory, stat '/opt/node_app/public/avatars//public/avatars/94459807-a717-46d1-9407-3478871c2685'"
}
When using this code:
let path = toSystemPath(this.parseRequired(this.parse(options.local_path), 'string', 'fs.exists: path is required.'));
Obviously things are going wrong here: /public/avatars//public/avatars/
The exact same attempt on the non-docker remote works fine.