Hi there, I have a javascript API integration to post form data to my backend webhook, including uploaded files. I’ve implemented the javascript to base64 encode the contents of the files when present and that part is working. The webhook also works, EXCEPT when there are files. It simply never comes through and there are no errors logged to the console or anything. Is there a max payload size that I’m exceeding or something? Code below:
// Javascript rule code
function readAsDataUri(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.addEventListener('loadend', (e) => {
if (typeof reader.result === 'string') {
resolve(reader.result);
} else {
reject(reader.error);
}
});
reader.readAsDataURL(file);
});
}
const API_URL = `https://<my_domain_here>/api/application/`;
let fields = {};
for (const [key, value] of Object.entries(feathery.fields)) {
fields[key] = feathery.fields[key].value;
}
const urlParams = new URLSearchParams(window.location.search);
const formId = urlParams.get('_slug');
let uploads = fields.uploads;
let uploadsResolved = [];
console.log('uploads', uploads);
if (uploads && uploads.length) {
console.log('uploads.length', uploads.length);
uploads = await Promise.all(uploads);
let contents = [];
uploads.forEach(f => contents.push(readAsDataUri(f)) );
contents = await Promise.all(contents);
contents.forEach((val, idx) => {
uploadsResolved.push({
name: uploads[idx].name,
size: uploads[idx].size,
type: uploads[idx].type,
contents: contents[idx]
});
})
}
fields.uploads = uploadsResolved;
console.log('fields.uploads', fields.uploads);
const payload = {
formId: formId,
fields: fields,
userId: feathery.userId,
stepProperties: feathery.getStepProperties(),
completed: feathery.isLastStep(),
isTestForm: feathery.isTestForm()
}
console.log('payload', payload);
feathery.http.post(API_URL, payload);