Variable Value from DB Not Displaying?

Hey Guys,

Performing a DB Single Query and returning a few values (as you cant see on POSTMAN Response).

When I input this into the next function it is not returning the actual value but rather the “Variable” itself (See screenshots).

NOTE - Hardcoding the URL works fine so it has something to do with the way the variable is setup / being accepted.

Any Ideas?

Did you manually type those {{ }} into the Set Value field?

Make sure you use the Code section, and there you don’t use {{ }}

No everything is set correctly as you’d expect.

I tested with pushing same to a “Set” variable for testing and works correct there so not sure what the hell is going on!

For further evolution on this topic you have to post a screenshot of the erroneous step/chain of steps :slight_smile:

Is this a custom module?

Sorry! Running around with my 2 toddler boys today so been chaotic!

Alright so attached is additional photos for the POSTMAN response for the DB Query / As well as Returning the “URL” value in the custom module (download_URL).

Then below is the code for the Custom Module.

Not sure what else would be helpful.

If I hardcode the actual URL for testing in the “URL” input for the custom module, it works flawlessly, so there is just something happening with the variable side.

Lemme know if anything else would be helpful and I will keep pluggin away. After the module you’ll see my Console Debugging mode in Wappler.

        const fs = require('fs');
    const axios = require('axios'); // you will need to install this
    const { toSystemPath } = require('../../../lib/core/path');

    exports.downloadImgUrl = async function (options) {

        let url = options.url

        // const srcImgPath = options.path;  //image path on the server
        const srcImgName = this.parse(options.img_name);

        // BELOW WORKS BUT NEEDS SHORTER SRC NAME NOT WORK WITH LONG NAME
        const destinationImagePath = `uploads/temp_usr_upload/${srcImgName}.png`;    //where new image will be saved

        var dir = 'uploads/temp_usr_upload'; // checking if directory exists, otherwise create new
        if (!fs.existsSync(dir)) {
            fs.mkdirSync(dir);
        }

        let path = toSystemPath(this.parseRequired(this.parse(options.path), 'string', 'fs.exists: path is required.'))
        let srcPath = fs.createReadStream(path);
        async function downloadImage(url, path) {
            const response = await axios({
                url,
                method: 'GET',
                responseType: 'stream'
            });
            return new Promise((resolve, reject) => {
                response.data.pipe(fs.createWriteStream(destinationImagePath))
                    .on('error', reject)
                    .once('close', () => resolve(destinationImagePath));
            });
        }

        downloadImage(url, path);

        return url;

    }

RESPONSE IN WAPPLER CONSOLE BELOW (AXIOS ERROR DUE TO VARIABLE)

  response: {
status: 400,
statusText: 'Bad Request',
headers: {
  date: 'Sun, 20 Mar 2022 01:43:27 GMT',
  server: 'Apache/2.4.51 (Unix)',
  'content-length': '226',
  connection: 'close',
  'content-type': 'text/html; charset=iso-8859-1'
},
config: {
  transitional: [Object],
  adapter: [Function: httpAdapter],
  transformRequest: [Array],
  transformResponse: [Array],
  timeout: 0,
  xsrfCookieName: 'XSRF-TOKEN',
  xsrfHeaderName: 'X-XSRF-TOKEN',
  maxContentLength: -1,
  maxBodyLength: -1,
  validateStatus: [Function: validateStatus],
  headers: [Object],
  url: '{{db_query_find_img.cf_url_org}}',
  method: 'get',
  responseType: 'stream',
  data: undefined
},
request: <ref *1> ClientRequest {
  _events: [Object: null prototype],
  _eventsCount: 7,
  _maxListeners: undefined,
  outputData: [],
  outputSize: 0,
  writable: true,
  destroyed: false,
  _last: true,
  chunkedEncoding: false,
  shouldKeepAlive: false,
  maxRequestsOnConnectionReached: false,
  _defaultKeepAlive: true,
  useChunkedEncodingByDefault: false,
  sendDate: false,
  _removedConnection: false,
  _removedContLen: false,
  _removedTE: false,
  _contentLength: 0,
  _hasBody: true,
  _trailer: '',
  finished: true,
  _headerSent: true,
  _closed: false,
  socket: [Socket],
  _header: 'GET %7B%7Bdb_query_find_img.cf_url_org%7D%7D HTTP/1.1\r\n' +
    'Accept: application/json, text/plain, */*\r\n' +
    'User-Agent: axios/0.25.0\r\n' +
    'Host: localhost\r\n' +
    'Connection: close\r\n' +
    '\r\n',
  _keepAliveTimeout: 0,
  _onPendingData: [Function: nop],
  agent: [Agent],
  socketPath: undefined,
  method: 'GET',
  maxHeaderSize: undefined,
  insecureHTTPParser: undefined,
  path: '%7B%7Bdb_query_find_img.cf_url_org%7D%7D',
  _ended: false,
  res: [IncomingMessage],
  aborted: false,
  timeoutCb: null,
  upgradeOrConnect: false,
  parser: null,
  maxHeadersCount: null,
  reusedSocket: false,
  host: 'localhost',
  protocol: 'http:',
  _redirectable: [Writable],
  [Symbol(kCapture)]: false,
  [Symbol(kNeedDrain)]: false,
  [Symbol(corked)]: 0,
  [Symbol(kOutHeaders)]: [Object: null prototype]
},
data: IncomingMessage {
  _readableState: [ReadableState],
  _events: [Object: null prototype],
  _eventsCount: 1,
  _maxListeners: undefined,
  socket: [Socket],
  httpVersionMajor: 1,
  httpVersionMinor: 1,
  httpVersion: '1.1',
  complete: true,
  rawHeaders: [Array],
  rawTrailers: [],
  aborted: false,
  upgrade: false,
  url: '',
  method: null,
  statusCode: 400,
  statusMessage: 'Bad Request',
  client: [Socket],
  _consuming: false,
  _dumped: false,
  req: [ClientRequest],
  responseUrl: 'http:%7B%7Bdb_query_find_img.cf_url_org%7D%7D',
  redirects: [],
  [Symbol(kCapture)]: false,
  [Symbol(kHeaders)]: [Object],
  [Symbol(kHeadersCount)]: 10,
  [Symbol(kTrailers)]: null,
  [Symbol(kTrailersCount)]: 0,
  [Symbol(RequestTimeout)]: undefined
}
},
isAxiosError: true,
toJSON: [Function: toJSON]
}

Try this:

let url = this.parseRequired(options.url, 'string', 'URL is required');

Without using one of the parse methods, it will only handle static values.

Here’s a list that describes better:

1 Like

SOLUTION: This does it!

Your the man!