This method adds a media file to a license key using the media’s binary representation.

Endpoint

POST:
https://messaging.esendex.us/Messaging.svc/CreateMediaFromContent

Syntax

CreateMediaFromContent(Request)

Request Parameters

Parameter NameDescriptionData TypeRequiredSample Value
Base64EncodedContentContent of the media file to create. This is binary data that is encoded as a string of base-64 digits.StringTrue
FileNameName of the media file to create.StringTrueMonkeyPic.jpg
LicenseKeyYour license key.GUIDTrue00000000-0000-0000-0000-000000000000
TagsCategory of the media file.Array of String valuesFalseanimal

Response

Returns: MediaMetadata object

Code Samples

You can use any programming language you want with our API, as long as it can make a REST or SOAP call. Here are examples for some of the most common platforms.

C#

// https://messaging.esendex.us/Messaging.svc?wsdl was added as a Service Reference and given the name WSDL

using WSDL;

var client = new MessagingClient(MessagingClient.EndpointConfiguration.mms2wsHttpBindingSecure);

var request = new CreateMediaContentRequest
{
    Base64EncodedContent = "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAGdYAABnWARjRyu0AAAASSURBVBhXY3gro4IVDSkJGRUAmbtLQUb26xsAAAAASUVORK5CYII=",
    Filename = "MyPhoto.jpg",
    LicenseKey = YOUR_LICENSE_KEY,
    Tags = new[] { "Photo" }
};

var media = await client.CreateMediaFromContentAsync(request);

if (media is null)
{
    Console.WriteLine("The media could not be created.");
    return;
}

Console.WriteLine(
    "UTC File Date: " + media.FileDate + Environment.NewLine +
    "File Name: " + media.FileName + Environment.NewLine +
    "File Size: " + media.FileSize + Environment.NewLine +
    "Media ID: " + media.MediaId + Environment.NewLine +
    "Mime Type: " + media.MimeType
);

foreach (var tag in media.Tags)
{
    Console.WriteLine("Tags: " + tag);
}

Java

import java.io.File;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.HttpURLConnection;
import org.apache.commons.io.IOUtils;

public final class CreateMediaFromContent {

    public static void main(String[] args) throws Exception {

        String responseContent = "";
        String response = "";
        String decoded = IOUtils.toString(new FileInputStream(new File("C:UsersDesktopBase64.txt")), "UTF-8");

        URL url = new URL("https://messaging.esendex.us/Messaging.svc/CreateMediaFromContent");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        StringBuilder sb = new StringBuilder("<CreateMediaContentRequest xmlns="https://messaging.esendex.us">");
        sb.append("<Base64EncodedContent>").append(decoded).append("</Base64EncodedContent>");
        sb.append("<Filename>JavaMonkey.jpg</Filename>");
        sb.append("<LicenseKey>00000000-0000-0000-0000-000000000000</LicenseKey>");
        sb.append("<Tags>");
        sb.append("<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Monkey</string>");
        sb.append("</Tags>");
        sb.append("</CreateMediaContentRequest>");

        connection.setRequestProperty("Content-Length", String.valueOf(sb.toString().length()));
        connection.setRequestProperty("Content-Type", "text/xml");
        connection.setRequestProperty("Connection", "Close");
        connection.setRequestProperty("SoapAction", "");
        connection.setRequestMethod("POST");
        connection.setDoInput(true);
        connection.setDoOutput(true);

        PrintWriter pw = new PrintWriter(connection.getOutputStream());
        pw.write(sb.toString());
        pw.flush();
        connection.connect();

        System.out.println(sb.toString());
        BufferedReader br;

        if (connection.getResponseCode() == 200) {
            br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        } else {
            br = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
        }

        while ((responseContent = br.readLine()) != null) {
            response += responseContent;
        }
        System.out.println(response);
    }
}

JavaScript

const url = 'https://messaging.esendex.us/Messaging.svc/CreateMediaFromContent';
const response = await fetch(url, {
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        'Base64EncodedContent': 'iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAGdYAABnWARjRyu0AAAASSURBVBhXY3gro4IVDSkJGRUAmbtLQUb26xsAAAAASUVORK5CYII=',
        'Filename': 'MyPhoto.jpg',
        'LicenseKey': '00000000-0000-0000-0000-000000000000',
        'Tags': ['Photo']
    }),
    method: 'POST'
});
const messages = await response.json();

console.log(messages);

JSON POST Request

{
	"Base64EncodedContent": "String content",
	"Filename": "String content",
	"LicenseKey": "1627aea5-8e0a-4371-9022-9b504344e724",
	"Tags": [
		"String content"
	]
}

JSON Response

{
	"FileDate": "/Date(928164000000-0400)/",
	"FileName": "String content",
	"FileSize": 9223372036854775807,
	"MediaId": 9223372036854775807,
	"MimeType": "String content",
	"Tags": [
		"String content"
	]
}

PHP with cURL

<?php

$json = '{
  "Base64EncodedContent":"aa/9j/4AAQSkZJRgABAQAAAQABAAD/2Q==",
  "Filename":"monkey.jpg",
  "LicenseKey":"00000000-0000-0000-0000-000000000000",
  "Tags":["Monkey"]
}';

$url = 'https://messaging.esendex.us/Messaging.svc/CreateMediaFromContent';
$cURL = curl_init();

curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_POST, true);
curl_setopt($cURL, CURLOPT_POSTFIELDS, $json);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);

curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
// If you desire your results in XML format, use the following line for your HTTP headers and comment out the HTTP headers code line above.
// curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

$result = curl_exec($cURL);
curl_close($cURL);
$array = json_decode($result, true);

// print_r($json);
// print_r("nnnn");
print_r($array);

?>

Python

import httpx

headers = {"Accept": "application/json"}
url = "https://messaging.esendex.us/Messaging.svc/CreateMediaFromContent"

request = {
    "Base64EncodedContent": "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAGdYAABnWARjRyu0AAAASSURBVBhXY3gro4IVDSkJGRUAmbtLQUb26xsAAAAASUVORK5CYII=",
    "Filename": "MyPhoto.jpg",
    "LicenseKey": "00000000-0000-0000-0000-000000000000",
    "Tags": ["Photo"],
}

with httpx.Client(headers=headers) as client:
    response = client.post(url=url, json=request)

response.raise_for_status()

if response.text == "":
    raise RuntimeError("The media could not be created.")

print(response.json())

Ruby

require 'json'
require 'net/http'

headers = { Accept: 'application/json', 'Content-Type': 'application/json' }
uri = URI('https://messaging.esendex.us/Messaging.svc/CreateMediaFromContent')

data = {
  'Base64EncodedContent': 'iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAGdYAABnWARjRyu0AAAASSURBVBhXY3gro4IVDSkJGRUAmbtLQUb26xsAAAAASUVORK5CYII=',
  'Filename': 'MyPhoto.jpg',
  'LicenseKey': '00000000-0000-0000-0000-000000000000',
  'Tags': ['Photo']
}.to_json

response = Net::HTTP.post(uri, data, headers)
raise response.message if response.is_a?(Net::HTTPClientError) || response.is_a?(Net::HTTPServerError)

puts JSON.parse(response.body)

XML POST Request

<CreateMediaContentRequest xmlns="http://sms2.cdyne.com">
  <Base64EncodedContent>String content</Base64EncodedContent>
  <Filename>String content</Filename>
  <LicenseKey>1627aea5-8e0a-4371-9022-9b504344e724</LicenseKey>
  <Tags>
    <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">String content</string>
    <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">String content</string>
  </Tags>
</CreateMediaContentRequest>

XML Response

<MediaMetadata xmlns="http://sms2.cdyne.com">
  <FileDate>1999-05-31T11:20:00</FileDate>
  <FileName>String content</FileName>
  <FileSize>9223372036854775807</FileSize>
  <MediaId>9223372036854775807</MediaId>
  <MimeType>String content</MimeType>
  <Tags>
    <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">String content</string>
    <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">String content</string>
  </Tags>
</MediaMetadata>

Let’s get your business buzzing

Spark customer connections in minutes. Discover the full power of our mobile messaging platform—no hidden fees, just real results.