How do I get access to the actual file content of a file in a fileobject?

Hi. I want to send file data from Appfarm to an 3rd-party provider. I want to save the filecontent as a string in filetype/base64 format in an appfarm variable for constructing my . I’ve already figured that I can send a web request to the filecontentLink in the file object - and I am recieving the response. However, I can’t seem to figure out how I access the data in the data parser. Does anyone have an idea?

{
“requestConfig”: {
“url”: “https://storage.googleapis.com/xiq-60b90b7c2bc1dc28804fd34a/dev/60e2ec24f1481804501377cc/63bede13ee1c6d603331a60e?GoogleAccessId=data-service@appfarm-187305.iam.gserviceaccount.com&Expires=1673496275&Signature=fthJzG%2FhE%2BupFkfoztfuGVhFA81JMAbv0mfXX%2BHLb7Xmz5bKv3doA0BqoELkqTuF3Z6J5HM7akPCeE%2Fj1CkRXhve%2BrXtHAkDtibyxavSECY54crl492O2Sg%20eCZoqSFLVBuqmc2%2FY0Ba5g8Oh%2Bo6NDuTG1Ofs6OrV%2Bfb3DyLwld0p2XC%2BMH3UdWvAQbGoO87mjmS%2Fxoc56gRt%2BYnoLDNoPNN%2FLAca9hpJNVVtPW21UOY6fjR%2Fe73Lc1JVdRKly0lTXC%2FkI6H%2FmbIBer3oGMQo5gHwhPk5fk2%2Bg%3D%3D”,
“headers”: {}
},
“responseData”: {
“status”: 200,
“statusText”: “OK”,
“rawData”: {},
“parsedData”: {
“type”: “Buffer”,
“data”: [
137,
80,
78,
71,
13,
10,
26,
10,
0,
0,
0,
13,
73,
72,
68,
82,
0,
0,
4,
176,
0,
0,
3,
32,
8,
6,
0,
0,
0,
51,
224,
155,
2,
0,
0,
0,
1,
115,
82,
71,
66,
0,
174,
206,
28,
233,
0,
0,
32,
0,
181,
249,
122,
125,
151,
183,
51,
176,
188,
233,
103,
115,
195,
165,
166,
20,
210,
201,
51,
176,
234,
219,
3,
205,
219,
177,
55,
165,
14,

Hi!

I believe a Service is set up in the Showroom for something similar. See endpoint “Send file”.

Summarized: use web request towards the appfarm fileContent URL. Responsetype = Arraybuffer. Resultparser using b2a (binary-to-ascii conversion).

Hi. I found it and tried - however it does not work. See pictures underneath:

When copying the exact code that was in the example you mentioned, I get this (empty base64content):

However when I set the response type to JSON, I get this:

So, you have response type ArrayBuffer, and the following result parser in the web request?

let base64content = btoa(String.fromCharCode(...new Uint8Array(rawResponseData)))
return {base64content}

I’ve seen cases where the spread-operator (…new) causes the btoa to fail (to many arguments). I’m not a javascript expert, but I guess it’s possible to rewrite the expression without the spread-operator.

I’ve only used this on PDFs. If it still does not work, you might try to see if chatGPT or google has another good expression of converting a binary PNG file to base64 string

Hi. Thanks for the help. I managed to get it by just using the function like this in the parser:

let base64content = btoa(rawResponseData)
return {base64content}
1 Like