Difference between revisions of "CreateMediaFromContent"

From CDYNE Wiki
Jump to navigation Jump to search
imported>Bdriggers
(Created page with "Create and add media to your SMS Notify! license key from the Base64 representation of the image. == CreateMediaFromContent Request == {| class="wikitable" |- ! align="le...")
 
(14 intermediate revisions by one other user not shown)
Line 1: Line 1:
==Request Examples ==
+
Create and add media to your SMS Notify! license key from the Base64 representation of the image.
  
== JSON ==
+
== CreateMediaFromContent Request ==
  
 +
{| class="wikitable"
 +
 +
|-
 +
! align="left" | '''Parameter Name'''
 +
! align="left" | '''Data Type'''
 +
! align="left" | '''Sample Input'''
 +
! align="left" | '''Required'''
 +
|-
 +
 +
| '''Bae64EncodedContent:'''  String representation of media. 
 +
|''String''
 +
| \/9j\/4AAQSkZJRgABAQAAAQABAAD\
 +
| TRUE
 +
|-
 +
 +
| '''FileName:'''  Name of media file being created.
 +
|''String''
 +
| MonkeyPic.jpg
 +
| TRUE
 +
|-
 +
 +
| '''LicenseKey:''' License key attached to media file. <br>[https://cdyne.com/register?qs=34&tk=true Trial Key] <br>[https://cdyne.com/register?qs=34 Production Key]
 +
| ''GUID''
 +
| f01d89fd-5155-5455-5585-e84ab8de8591
 +
|TRUE
 +
|-
 +
 +
| '''Tag:''' Category of new media.
 +
| ''String''
 +
| Monkey
 +
|FALSE
 +
|-
 +
|}
 +
 +
== CreateMediaFromContent Response ==
 +
 +
{| class="wikitable"
 +
 +
|-
 +
! align="left" | '''Parameter Name'''
 +
! align="left" | '''Data Type'''
 +
! align="left" | '''Sample Output'''
 +
|-
 +
 +
| '''FileDate:'''  UTC date and time media was created.
 +
|''DateTime''
 +
| 1999-05-31T11:20:00
 +
|-
 +
 +
| '''FilenName:''' Name of media file.
 +
| ''String''
 +
| MonkeyPic.jpg
 +
|-
 +
 +
| '''FileSize:''' Size of media file..
 +
| ''Int''
 +
| 97465
 +
|-
 +
 +
| '''MediaId:''' Unique ID for specific media file.
 +
| ''Int''
 +
| 12487
 +
|-
 +
 +
| '''MimeType:''' Media file type.
 +
| ''String''
 +
| image/jpeg
 +
|-
 +
 +
| '''Tag:''' Category of media file.
 +
| ''String''
 +
| Monkey
 +
|-
 +
|}
 +
 +
== JSON Request ==
 +
 +
The following is an example POST request using http://messaging.cdyne.com/Messaging.svc/CreateMediaFromContent
 +
 
<PRE>
 
<PRE>
 
{
 
{
Line 11: Line 90:
 
}
 
}
 
</PRE>
 
</PRE>
 +
 +
== Ruby ==
 +
<syntaxhighlight lang="ruby" line="line">
 +
require 'uri'
 +
require 'net/http'
 +
 +
url = URI("http://messaging.cdyne.com/Messaging.svc/CreateMediaFromContent")
 +
 +
http = Net::HTTP.new(url.host, url.port)
 +
 +
request = Net::HTTP::Post.new(url)
 +
 +
request["content-type"] = 'application/json'
 +
 +
request.body = '{
 +
        "Base64EncodedContent":"aa/9j/4AAQSkZJRgABAQAAAQABAAD/2Q==",
 +
"Filename":"monkey.jpg",
 +
"LicenseKey":"f01d89fd-5155-5455-5585-e84ab8de8591",
 +
"Tags":["Monkey"]}'
 +
 +
response = http.request(request)
 +
 +
puts response.read_body
 +
gets response.read_body
 +
 +
</syntaxhighlight>
  
 
== C# ==
 
== C# ==
  
<code type=csharp>
+
<syntaxhighlight lang="csharp" line="line">
  
 
/*http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL*/
 
/*http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL*/
Line 55: Line 160:
 
     }
 
     }
 
}
 
}
</code>
+
</syntaxhighlight>
  
 
== VB.Net ==
 
== VB.Net ==
  
<code type=vbnet>
+
<syntaxhighlight lang="vbnet" line="line">
  
 
'http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL
 
'http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL
Line 68: Line 173:
  
 
     Sub Main()
 
     Sub Main()
 +
 
         Dim client As WSDL.MessagingClient = New MessagingClient("mms2wsHttpBinding")
 
         Dim client As WSDL.MessagingClient = New MessagingClient("mms2wsHttpBinding")
  
Line 97: Line 203:
 
End Module
 
End Module
  
</code>
+
</syntaxhighlight>
 +
 
 +
== PHP with cURL ==
 +
<syntaxhighlight lang="php" line="line">
 +
<?php
 +
 
 +
$json='{
 +
"Base64EncodedContent":"aa/9j/4AAQSkZJRgABAQAAAQABAAD/2Q==",
 +
"Filename":"monkey.jpg",
 +
"LicenseKey":"f01d89fd-5155-5455-5585-e84ab8de8591",
 +
"Tags":["Monkey"]
 +
      }';
 +
 
 +
$url='http://messaging.cdyne.com/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 httpheaders and comment out the httpheaders 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("\n\n\n\n");
 +
 
 +
print_r($array);
 +
 
 +
?>
 +
</syntaxhighlight>
 +
 
 +
== VBScript ==
 +
<syntaxhighlight lang="vb" line="line">
 +
 
 +
Dim cXML
 +
cXML = "<CreateMediaContentRequest xmlns=""http://sms2.cdyne.com"">" & _
 +
"<Base64EncodedContent>aa/9j/4AAQSkZJRgABAQAAAQABAAD/2Q==</Base64EncodedContent>" & _
 +
"<Filename>vbsmonkey.jpg</Filename>" & _
 +
  "<LicenseKey>f01d89fd-5155-5455-5585-e84ab8de8591</LicenseKey>" & _
 +
  "<Tags>" & _
 +
    "<string xmlns=""http://schemas.microsoft.com/2003/10/Serialization/Arrays"">vbstest</string>" & _
 +
  "</Tags>" & _
 +
"</CreateMediaContentRequest>"
 +
 
 +
Dim oXMLHTTP
 +
Set oXMLHTTP = CreateObject("Microsoft.XMLHTTP")
 +
Set oDoc = CreateObject("MSXML2.DOMDocument")
 +
Call oXMLHttp.Open("POST", "http://messaging.cdyne.com/Messaging.svc/CreateMediaFromContent", False)
 +
Call oXMLHttp.setRequestHeader("Content-Type", "text/xml")       
 +
Call oXMLHttp.send(cXML)
 +
 
 +
MsgBox oXMLHTTP.responseText
 +
 
 +
Const ForReading = 1, ForWriting = 2, ForAppending = 8
 +
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
 +
Dim fso, MyFile, FileName, TextLine
 +
Set fso = CreateObject("Scripting.FileSystemObject")
 +
FileName = "c:\Users\Desktop\MMS.txt"
 +
Set MyFile = fso.OpenTextFile(FileName, ForWriting, True)
 +
MyFile.WriteLine oXMLHttp.responseText
 +
MyFile.Close
 +
Set MyFile = fso.OpenTextFile(FileName, ForReading)
 +
Do While MyFile.AtEndOfStream <> True
 +
TextLine = MyFile.ReadLine
 +
Loop
 +
 
 +
MyFile.Close
 +
 
 +
set request = nothing
 +
</syntaxhighlight>
 +
 
 +
== JAVA ==
 +
<syntaxhighlight lang="java" line="line">
 +
 
 +
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:\\Users\\Desktop\\Base64.txt")), "UTF-8");
 +
 
 +
        URL url = new URL("http://messaging.cdyne.com/Messaging.svc/CreateMediaFromContent");
 +
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
 +
 
 +
        StringBuilder sb = new StringBuilder("<CreateMediaContentRequest xmlns=\"http://sms2.cdyne.com\">");
 +
        sb.append("<Base64EncodedContent>").append(decoded).append("</Base64EncodedContent>");
 +
        sb.append("<Filename>JavaMonkey.jpg</Filename>");
 +
        sb.append("<LicenseKey>f01d89fd-5155-5455-5585-e84ab8de8591</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);
 +
    }
 +
}
 +
</syntaxhighlight>

Latest revision as of 11:20, 11 January 2019

Create and add media to your SMS Notify! license key from the Base64 representation of the image.

CreateMediaFromContent Request

Parameter Name Data Type Sample Input Required
Bae64EncodedContent: String representation of media. String \/9j\/4AAQSkZJRgABAQAAAQABAAD\ TRUE
FileName: Name of media file being created. String MonkeyPic.jpg TRUE
LicenseKey: License key attached to media file.
Trial Key
Production Key
GUID f01d89fd-5155-5455-5585-e84ab8de8591 TRUE
Tag: Category of new media. String Monkey FALSE

CreateMediaFromContent Response

Parameter Name Data Type Sample Output
FileDate: UTC date and time media was created. DateTime 1999-05-31T11:20:00
FilenName: Name of media file. String MonkeyPic.jpg
FileSize: Size of media file.. Int 97465
MediaId: Unique ID for specific media file. Int 12487
MimeType: Media file type. String image/jpeg
Tag: Category of media file. String Monkey

JSON Request

The following is an example POST request using http://messaging.cdyne.com/Messaging.svc/CreateMediaFromContent

{
	"Base64EncodedContent":"aa/9j/4AAQSkZJRgABAQAAAQABAAD/2Q==",
	"Filename":"monkey.jpg",
	"LicenseKey":"f01d89fd-5155-5455-5585-e84ab8de8591",
	"Tags":["Monkey"]
}

Ruby

 1 require 'uri'
 2 require 'net/http'
 3 
 4 url = URI("http://messaging.cdyne.com/Messaging.svc/CreateMediaFromContent")
 5 
 6 http = Net::HTTP.new(url.host, url.port)
 7 
 8 request = Net::HTTP::Post.new(url)
 9 
10 request["content-type"] = 'application/json'
11 
12 request.body = '{
13         "Base64EncodedContent":"aa/9j/4AAQSkZJRgABAQAAAQABAAD/2Q==",
14 	"Filename":"monkey.jpg",
15 	"LicenseKey":"f01d89fd-5155-5455-5585-e84ab8de8591",
16 	"Tags":["Monkey"]}'
17 
18 response = http.request(request)
19 
20 puts response.read_body
21 gets response.read_body

C#

 1 /*http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL*/
 2 
 3 using System;
 4 using System.Collections.Generic;
 5 using System.Linq;
 6 using System.Text;
 7 using System.Threading.Tasks;
 8 using CreateMediaFromContent.WSDL;
 9 
10 namespace CreateMediaFromContent
11 {
12     class Program
13     {
14         static void Main(string[] args)
15         {
16             MessagingClient client = new MessagingClient("mms2wsHttpBinding");
17             CreateMediaContentRequest req = new CreateMediaContentRequest();
18             req.Base64EncodedContent = "aa/9j/4AAQSkZJRgABAQAAAQABAAD/2Q==";
19             req.Filename = "Monkey14.jpg";
20             req.LicenseKey = new Guid("f01d89fd-5155-5455-5585-e84ab8de8591");
21             req.Tags = new string[] {"Monkey"};
22 
23             MediaMetadata resp = client.CreateMediaFromContent(req);
24 
25             Console.WriteLine("UTC File Date: " + resp.FileDate + Environment.NewLine +
26                 "File Name: " + resp.FileName + Environment.NewLine +
27                 "File Size: " + resp.FileSize + Environment.NewLine +
28                 "Media ID: " + resp.MediaId + Environment.NewLine +
29                 "Mime Type: " + resp.MimeType);
30 
31             foreach (var item in resp.Tags)
32             {
33                 Console.Write("{0}", "Tags: " + item + Environment.NewLine + Environment.NewLine);
34             }
35 
36             Console.ReadLine();
37         }
38     }
39 }

VB.Net

 1 'http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL
 2 
 3 Imports CreateMediaFromContent.WSDL
 4 
 5 Module Module1
 6 
 7     Sub Main()
 8 
 9         Dim client As WSDL.MessagingClient = New MessagingClient("mms2wsHttpBinding")
10 
11         Dim req As New WSDL.CreateMediaContentRequest()
12 
13         req.Base64EncodedContent = "aa/9j/4AAQSkZJRgABAQAAAQABAAD/2Q=="
14         req.Filename = "VBNetMonkey.jpg"
15         req.LicenseKey = New Guid("f01d89fd-5155-5455-5585-e84ab8de8591")
16         req.Tags = New String() {"Monkey"}
17 
18         Dim resp As WSDL.MediaMetadata = client.CreateMediaFromContent(req)
19 
20         Console.WriteLine("UTC File Date: " + Convert.ToString(resp.FileDate) + Environment.NewLine +
21                           "File Name: " + resp.FileName + Environment.NewLine +
22                           "File Size: " + Convert.ToString(resp.FileSize) + Environment.NewLine +
23                           "Media ID: " + Convert.ToString(resp.MediaId) + Environment.NewLine +
24                           "Mime Type: " + resp.MimeType)
25 
26         For Each item In resp.Tags
27 
28             Console.WriteLine("Tags: " + item + Environment.NewLine + Environment.NewLine)
29 
30         Next
31 
32         Console.ReadLine()
33 
34     End Sub
35 
36 End Module

PHP with cURL

 1 <?php
 2 
 3 $json='{
 4 	"Base64EncodedContent":"aa/9j/4AAQSkZJRgABAQAAAQABAAD/2Q==",
 5 	"Filename":"monkey.jpg",
 6 	"LicenseKey":"f01d89fd-5155-5455-5585-e84ab8de8591",
 7 	"Tags":["Monkey"]
 8        }';
 9 
10 $url='http://messaging.cdyne.com/Messaging.svc/CreateMediaFromContent';
11 $cURL = curl_init();
12  
13 curl_setopt($cURL,CURLOPT_URL,$url);
14 curl_setopt($cURL,CURLOPT_POST,true);
15 curl_setopt($cURL,CURLOPT_POSTFIELDS,$json);
16 curl_setopt($cURL,CURLOPT_RETURNTRANSFER, true);  
17 curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));
18 //If you desire your results in xml format, use the following line for your httpheaders and comment out the httpheaders code line above.
19 //curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
20 $result = curl_exec($cURL);
21 
22 curl_close($cURL);
23 
24 $array = json_decode($result, true);
25 //print_r($json);
26 //print_r("\n\n\n\n");
27 
28 print_r($array);
29 
30 ?>

VBScript

 1 Dim cXML
 2 cXML = "<CreateMediaContentRequest xmlns=""http://sms2.cdyne.com"">" & _
 3 "<Base64EncodedContent>aa/9j/4AAQSkZJRgABAQAAAQABAAD/2Q==</Base64EncodedContent>" & _
 4 "<Filename>vbsmonkey.jpg</Filename>" & _
 5   "<LicenseKey>f01d89fd-5155-5455-5585-e84ab8de8591</LicenseKey>" & _
 6   "<Tags>" & _
 7     "<string xmlns=""http://schemas.microsoft.com/2003/10/Serialization/Arrays"">vbstest</string>" & _
 8   "</Tags>" & _
 9 "</CreateMediaContentRequest>"
10 
11 Dim oXMLHTTP
12 Set oXMLHTTP = CreateObject("Microsoft.XMLHTTP")
13 Set oDoc = CreateObject("MSXML2.DOMDocument")
14 Call oXMLHttp.Open("POST", "http://messaging.cdyne.com/Messaging.svc/CreateMediaFromContent", False)
15 Call oXMLHttp.setRequestHeader("Content-Type", "text/xml")        
16 Call oXMLHttp.send(cXML)
17 
18 MsgBox oXMLHTTP.responseText 
19 
20 Const ForReading = 1, ForWriting = 2, ForAppending = 8
21 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
22 Dim fso, MyFile, FileName, TextLine
23 Set fso = CreateObject("Scripting.FileSystemObject")
24 FileName = "c:\Users\Desktop\MMS.txt"
25 Set MyFile = fso.OpenTextFile(FileName, ForWriting, True)
26 MyFile.WriteLine oXMLHttp.responseText
27 MyFile.Close
28 Set MyFile = fso.OpenTextFile(FileName, ForReading)
29 Do While MyFile.AtEndOfStream <> True
30 TextLine = MyFile.ReadLine
31 Loop
32 
33 MyFile.Close
34 
35 set request = nothing

JAVA

 1 import java.io.File;
 2 import java.io.PrintWriter;
 3 import java.io.BufferedReader;
 4 import java.io.FileInputStream;
 5 import java.io.InputStreamReader;
 6 import java.net.URL;
 7 import java.net.HttpURLConnection;
 8 import org.apache.commons.io.IOUtils;
 9 
10 public final class CreateMediaFromContent {
11 
12     public static void main(String[] args) throws Exception {
13 
14         String responseContent = "";
15         String response = "";
16         String decoded = IOUtils.toString(new FileInputStream(new File("C:\\Users\\Desktop\\Base64.txt")), "UTF-8");
17 
18         URL url = new URL("http://messaging.cdyne.com/Messaging.svc/CreateMediaFromContent");
19         HttpURLConnection connection = (HttpURLConnection) url.openConnection();
20 
21         StringBuilder sb = new StringBuilder("<CreateMediaContentRequest xmlns=\"http://sms2.cdyne.com\">");
22         sb.append("<Base64EncodedContent>").append(decoded).append("</Base64EncodedContent>");
23         sb.append("<Filename>JavaMonkey.jpg</Filename>");
24         sb.append("<LicenseKey>f01d89fd-5155-5455-5585-e84ab8de8591</LicenseKey>");
25         sb.append("<Tags>");
26         sb.append("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">Monkey</string>");
27         sb.append("</Tags>");
28         sb.append("</CreateMediaContentRequest>");
29 
30         connection.setRequestProperty("Content-Length", String.valueOf(sb.toString().length()));
31         connection.setRequestProperty("Content-Type", "text/xml");
32         connection.setRequestProperty("Connection", "Close");
33         connection.setRequestProperty("SoapAction", "");
34         connection.setRequestMethod("POST");
35         connection.setDoInput(true);
36         connection.setDoOutput(true);
37 
38         PrintWriter pw = new PrintWriter(connection.getOutputStream());
39         pw.write(sb.toString());
40         pw.flush();
41         connection.connect();
42 
43         System.out.println(sb.toString());
44         BufferedReader br;
45 
46         if (connection.getResponseCode() == 200) {
47             br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
48         } else {
49             br = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
50         }
51 
52         while ((responseContent = br.readLine()) != null) {
53             response += responseContent;
54         }
55         System.out.println(response);
56     }
57 }