All Collections
API and Integration
MMS API attachment endcoding
MMS API attachment endcoding

Recommendations on how to base64 encode attachments for sending via MMS API

Amy avatar
Written by Amy
Updated over a week ago

MMS Attachments are required to be base64 encoded.

Below are some examples of how to encode an attachment in different programming languages.

PHP

$path = 'myfolder/myimage.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);

Java

private static String encodeFileToBase64Binary(String fileName) throws IOException {
File file = new File(fileName);
byte[] encoded = Base64.encodeBase64(FileUtils.readFileToByteArray(file));
return new String(encoded, StandardCharsets.US_ASCII);
}

Our full MMS API documentation is available here: MMS API

Did this answer your question?