Hi,
There is a way to do exactly what you need. The method involves fetching the file data of the document stored in Appfarm, converting said data to B64 and then sending it to an endpoint.
Before starting, you should have a look at our Docs for integrating with Signicat, which goes over most of the same steps.
The most relevant piece of code is this, for converting binary data to B64:
function convertBinToB64(binary) {
let res = new Uint8Array(binary);
const chunkSize = 10000;
const chunks = Math.ceil(res.length / chunkSize);
console.log({ chunkSize, chunks });
let result = "";
for (let i = 0; i < chunks; ++i) {
const part = res.slice(i * chunkSize, (i + 1) * chunkSize);
result += String.fromCharCode.apply(null, part);
}
let base64String = btoa(result);
console.log({base64String});
return base64String;
}
The Setup
(This setup will work in Services as well, but you have to use a Database Connected datasource, as Runtime Sources are not compatible with File Objects in Services. You can read more about datasources in our [Docs](https://docs.appfarm.io/reference/apps/data/data-sources) )
This is a very simple Action, consisting of 3 nodes. The first node reads the File Object to a Runtime Source. This File Object will contain many properties, one of which is a File Content URL. This is an address to where the binary data is stored. For Services, you must omit this Runtime Source, and instead use a Database Connected Source due to reasons explained above.
The second Action Node is a Web Request to the File Content URL. This will return an Arraybuffer, so you must change the Response Type to this. (Or else the Web Request will fail).
Inside the Result Parser of the second Action Node, a function converts the incoming rawResponseData
from the File Content URL to B64 and returns it in a JSON Object on the key b64
. Map b64
to a temporary place, like App Variables or Service Variables. In my first screenshot, I have mapped b64
to an App Variable called B64
.
In the last Action Node I send the B64 String to an Endpoint. For debugging purposes, you can use a site like Webhook.site, to view your request. (If you are comfortable with sending your test data to an unauthorized 3rd party).
In the 3rd screenshot is the Body that I POST to Webhook.site.
On the receving end, I get this:
You must ofcourse change this Body to match the excpected request at PowerOffice.
Reach out if there are any questions
// Erik