Error message when decoding long Base64 string

  • Goal:
    We are trying to decode a very long string of Base64 (which points to the url of a PDF) and then download the file in app.

  • Steps:
    Currently, we have a query in our app that searches multiple DB tables and successfully returns a truncated version of the encrypted Base64 in Retool. If we locate this in our DB, we can see it's much longer than what Retool is pulling.

However, if we use a select, from the specific table where we know the value is, and searching for the specific Base64 line, it returns this error message (see screenshot). This works in our DB. Could retool have a limit to pulling this in? The full encoded string in our DB is over 8000 characters. Thanks!

Hey @hannah.calderwood

Retool is truncating a long Base64 string from the database, causing decoding errors. This is likely due to Retool's string length limits. Consider server-side decoding or breaking the string into smaller chunks.

You can use the retool storage for it

4 Likes

Hi! Thanks so much for the response. We're struggling to break the string up into smaller chunks, right now we're using this query.
Have you successfully done this before? And if so, do you remember what logic you used? Thank you!

SELECT DBMS_LOB.SUBSTR(versiondata, Column1, Column2) AS chunk1,
  DBMS_LOB.SUBSTR(versiondata, Column1, Column3) AS chunk2,
  DBMS_LOB.SUBSTR(versiondata, Column1, Column4) AS chunk3,
  DBMS_LOB.SUBSTR(versiondata, Column1, Column5) AS chunk4,
  DBMS_LOB.SUBSTR(versiondata, Column1, Column6) AS chunk5,
  DBMS_LOB.SUBSTR(versiondata, Column1, Column7) AS chunk6,
  Value_Location FROM Table1
WHERE Value_Location = 'Value'
Will get the data from this query and merge in transformer
let base64Data =
       ({{query16.dataArray[0].CHUNK1[0] || '' }}+
       {{ query16.dataArray[0].CHUNK2[0] || '' }}+
       {{ query16.dataArray[0].CHUNK3[0] || '' }}+
       {{ query16.dataArray[0].CHUNK4[0] || '' }}+
       {{ query16.dataArray[0].CHUNK5[0] || '' }}+
       {{ query16.dataArray[0].CHUNK6[0] || '' }})
  .replace(/\s/g, '')   // remove all whitespace/newlines
  .replace(/[^A-Za-z0-9+/=]/g, ''); // remove any non-base64 characters;
// Only add padding if required
//  if (base64Data.length % 4 !== 0) {
//    base64Data = base64Data.padEnd(base64Data.length + (4 - base64Data.length % 4), '=');
//  }
return base64Data;

Hi @hannah.calderwood,

I believe Oracle should have some built in functions for decoding the base64. Here's an example with Postgres:

It looks like they have a decode function: UTL_ENCODE
and string conversion function: UTL_I18N

Does that help for your use case? :crossed_fingers: I'll tentatively mark this as a solution for visibility, but please reach out if it doesn't solve your case!

2 Likes