Previously working request parser function now fails with "FunctionEvalError: Invalid character"

I have a very simple web request that fetches an image from a File Object using the File Content URL of that object, then stores it as B64 encoded string in an App Variable.

I’m not sure when it stopped working, but when I ran the action today, I got this error:
image

If I remove the Result Parser, the request runs as you would expect. My parser:

let base64content = btoa(rawResponseData);

return {base64content};

I found out that if I check “Send from Client” at the top of the request, I can run the request with my parser with no errors, which makes me think this isn’t a user error on my part.

Hi Øyvind,

I just need some additional information :smile:

  • What kind of file are you attempting to base64?
  • If the file does not contain sensitive information, can you share it with me on a DM?
  • Also, just to clarify, are you doing a web request on the File Content URL of a File Object and then parsing the result to base64?

// Erik

Image file as JPEG, same as my profile picture here :wink:

me

Yes to everything on your third point. I’m also using ArrayBuffer as the response type.

I set up a small app to test: Appfarm

Upload an image, and press the buttons to try to turn it into B64 data. If you send the request from the client it works, but not from the server.

I see that the data returned is actually empty, so I guess that’s a clue. I assumed fetching from the file content URL would return the file data :thinking:

We have done some changes to atob() and btoa() in services and on the server-side, to make their behaviour more inline with how it works in your browser.

Are you able to confirm that your base64 conversion used to work and that the resulting base64 was valid?

We will continue to investigate on our end, but any additional information is appreciated :slightly_smiling_face:

Are you able to confirm that your base64 conversion used to work and that the resulting base64 was valid?

The app is still pre-users, so to be honest I can’t confirm it 100%

Looking at this logging data, I get the feeling it might have never worked to be honest.

It looks like fetching from the File Content URL using response type ArrayBuffer just returns a JSON with an empty data object.

image

I switched to response type JSON now, and I see the binary data inside the response. Now both types of requests fail, although with slightly different error messages.

Sending from server results in

FunctionEvalError: Invalid character

while the client variant results in

InvalidCharacterError: Failed to execute ‘btoa’ on ‘Window’: The string to be encoded contains characters outside of the Latin1 range.

The updated actions are on the mini-app I linked earlier.

Update:

Found a solution. Changed the parser to this:

let base64content = btoa(unescape(encodeURIComponent(rawResponseData)));

return {base64content};

Are your files being transmitted correctly with this solution? EncodeURIComponent replaces certain chars, with 2,3,4 bytes, altering your rawResponseData. Unescape does the same (and has different behaviour across browsers).

Do your files open normally, without corruption?

No, looks like it’s corrupted actually.

I just checked another app where I know for sure the decoding using btoa used to work, and it’s broken there too.

This update has influenced our functionality that used to work correctly.
Use case:
We are sending the base64 content in web request. It is done in 2 steps:

  1. To get a base64 version of file, we are making a web request to Attachment.File Content URL with Response Type: Arraybuffer and Response parser:
let base64content = btoa(rawResponseData);
return {base64content}
  1. We make a web-request with resulting base 64 content

Now it fails on the step 1 - when we are trying to get a base64 version of file with

FunctionEvalError: Invalid character

Screenshot 2024-05-23 at 15.55.42

Hi!

What type of files are you sending, and is it always failing? What does the web request body setup look like?

Hi!

It fails on any file type, and it is not a web request that is failing, but when we try to fetch base64 version of file to send it in the web request in the next action node.


Screenshot 2024-05-27 at 12.45.08
And result parser content is:

let base64content = btoa(rawResponseData);
return {base64content}

Result:

Screenshot 2024-05-27 at 12.45.48

That used to work before the recent Appfarm upgrade.