Web Messaging SDK file upload MIME validation failure

The Android app uses the sendFile method from the Genesys Cloud Web Messaging SDK to attach images, but the server rejects standard PNG files with a 400 Bad Request. The response body contains {"errorCode": "invalidFileFormat", "message": "File type not supported"}. The SDK docs list image/png as valid, yet the backend enforces a stricter allowlist. Need to know the exact accepted MIME types and size limits for the guest API.

Hey there.

This is a classic gotcha with the Web Messaging SDK, especially on mobile. The backend isn’t actually rejecting the PNG file itself; it’s rejecting the MIME type string being sent in the HTTP header or the metadata payload. Android’s file pickers sometimes return image/octet-stream or just image/png without the correct parameters, and Genesys Cloud’s gateway is strict about the Content-Type.

You need to intercept the file object before it hits sendFile. Check the actual MIME type string. If it’s anything other than image/png, image/jpeg, image/gif, or application/pdf, you’ll get that 400 error. Also, keep an eye on the file size. The hard limit for guest uploads is 5MB. Anything larger gets blocked before it even hits your validation logic.

Here’s a quick snippet to normalize the type and check the size before sending. This works well in a wrapper function around the SDK call:

const validateAndSendFile = async (file, conversationApi) => {
 // Allowed MIME types for Genesys Cloud Web Messaging
 const allowedTypes = [
 'image/png',
 'image/jpeg',
 'image/gif',
 'application/pdf'
 ];

 // Check size limit (5MB)
 if (file.size > 5 * 1024 * 1024) {
 throw new Error('File exceeds 5MB limit');
 }

 // Normalize MIME type if Android sends a generic type
 let mimeType = file.type;
 if (file.name.endsWith('.png') && !mimeType.includes('png')) {
 mimeType = 'image/png';
 } else if (file.name.endsWith('.jpg') || file.name.endsWith('.jpeg')) {
 mimeType = 'image/jpeg';
 }

 if (!allowedTypes.includes(mimeType)) {
 throw new Error(`Unsupported file type: ${mimeType}`);
 }

 // Now send with the corrected type
 await conversationApi.sendFile(conversationId, {
 file: file,
 contentType: mimeType // Explicitly set this
 });
};

Make sure you’re explicitly passing contentType in the payload. The SDK sometimes guesses wrong on Android. Also, verify your deployment settings in Genesys Cloud Admin under Integrations > Web Messaging > Deployments. There’s a toggle for Allow file uploads that must be enabled, and sometimes the allowed file types list there overrides the API defaults if it’s been customized by an admin. Check that list.