I'm using the Amazon Connect ChatJS library and trying to send an attachment, but it returns error 400 'Invalid request body'.
ChatJS's sendAttachment()
method accepts an object with attachment of HTML filetype. I'm using react-native-image-picker to select an image from the device, and converting to File
before passing it to the sendAttachment()
method, but it doesn't work. Does anyone know the solution for this?
This is how I'm converting the local imageUri
to a File
and triggering the handleSendAttachment()
function, which will then run the sendAttachment()
method of amazon-client-chatjs session:
const sendAttachment = async () => {
if (!attachment?.uri) {
return;
}
try {
const fileBlob = new Blob([attachment.uri], { type: 'image/jpeg' });
const file = new File([fileBlob], attachment.name);
handleSendAttachment(file, clearAttachment);
} catch (err) {
console.log('Error: ', err);
}
};