GetMedia

From CDYNE Wiki
Jump to navigation Jump to search

Retrieve the Base64 representation of a particular media file that was added to your SMS Notify! license key.

GetMedia Request

Parameter Name Data Type Sample Input Required
LicenseKey: License key attached to media file.
Trial Key
Production Key
GUID f01d89fd-5155-5455-5585-e84ab8de8591 TRUE
MediaID: Unique ID of specific media file.. Int 1772 TRUE

GetMedia Response

Parameter Name Data Type Sample Output
N/A Base64 String \/9j\/4AAQSkZJRgABAQAAAQABAAD\

HTTP GET Request

http://messaging.cdyne.com/Messaging.svc/GetMedia?LicenseKey=f01d89fd-5155-5455-5585-e84ab8de8591&MediaId=0001

Ruby

 1 require 'net/http'
 2 require 'URI' 
 3 
 4 puts URI.methods 
 5 
 6 url = URI.parse("http://messaging.cdyne.com/Messaging.svc/GetMedia?LicenseKey=f01d89fd-5155-5455-5585-e84ab8de8591&MediaId=0001")
 7 
 8 res = Net::HTTP.get_response(url) 
 9 
10 data = res.body 
11 
12 puts data
13 gets data

C#

 1 //The Base64 representation of the image will be printed in the console app window.
 2 
 3 /*http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL*/
 4 
 5 using System;
 6 using System.Collections.Generic;
 7 using System.Linq;
 8 using System.Text;
 9 using System.Threading.Tasks;
10 using GetMedia.WSDL;
11 using System.IO;
12 
13 namespace GetMedia
14 {
15     class Program
16     {
17         static void Main(string[] args)
18         {
19             MessagingClient client = new MessagingClient("mms2wsHttpBinding");
20             string resp = client.GetMedia(new Guid("f01d89fd-5155-5455-5585-e84ab8de8591"), 0001);
21 
22             Console.WriteLine(resp);
23             Console.ReadLine();
24         }
25     }
26 }
27 
28 
29 //Option to save the actual media.  The media will automatically saved to the location you specified.
30 
31 /*http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL*/
32 
33 using System;
34 using System.Collections.Generic;
35 using System.Linq;
36 using System.Text;
37 using System.Threading.Tasks;
38 using GetMedia.WSDL;
39 using System.IO;
40 using System.Diagnostics;
41 
42 namespace GetMedia
43 {
44     class Program
45     {
46         static void Main(string[] args)
47         {
48             string path = @"C:\Users\Desktop\image1.jpg";
49 
50             MessagingClient client = new MessagingClient("mms2wsHttpBinding");
51             string resp = client.GetMedia(new Guid("f01d89fd-5155-5455-5585-e84ab8de8591"), 001);
52             
53             var imagetest = Convert.FromBase64String(resp);
54 
55             File.WriteAllBytes(path, imagetest);
56 
57             Console.WriteLine("Image Saved");
58             Console.ReadLine();
59         }
60     }
61 }
62 
63 
64 //Option to display the actual media.  The media will automatically display when running the code and the image will be saved to the location you specified.
65 
66 /*http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL*/
67 
68 using System;
69 using System.Collections.Generic;
70 using System.Linq;
71 using System.Text;
72 using System.Threading.Tasks;
73 using GetMedia.WSDL;
74 using System.IO;
75 using System.Diagnostics;
76 
77 namespace GetMedia
78 {
79     class Program
80     {
81         static void Main(string[] args)
82         {
83             MessagingClient client = new MessagingClient("mms2wsHttpBinding");
84 
85             var info = client.GetMediaInfo(new MediaCriteria() { MediaId = 001, LicenseKey = new Guid("f01d89fd-5155-5455-5585-e84ab8de8591") });
86             var content = client.GetMedia(new Guid("f01d89fd-5155-5455-5585-e84ab8de8591"), 001);
87 
88             var contentBytes = Convert.FromBase64String(content);
89             var filename = $"{System.IO.Path.GetTempFileName()}{info.Media[0].FileName}";
90             File.WriteAllBytes(filename, contentBytes);
91             var process = Process.Start(filename);
92 
93         }
94     }
95 }

VB.Net

 1 'The Base64 representation of the image will be printed in the console app window.
 2 
 3 'http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL
 4 
 5 Imports GetMedia.WSDL
 6 
 7 Imports System.IO
 8 
 9 Module Module1
10 
11     Sub Main()
12 
13         Dim client As WSDL.MessagingClient = New MessagingClient("mms2wsHttpBinding")
14 
15         Dim resp As String = client.GetMedia(New Guid("f01d89fd-5155-5455-5585-e84ab8de8591"), 12441)
16 
17         Dim imagetest = Convert.FromBase64String(resp)
18 
19         File.WriteAllBytes("vbimage.jpg", imagetest)
20 
21         Console.WriteLine("Image Saved")
22 
23         Console.ReadLine()
24 
25     End Sub
26 
27 End Module
28 
29 
30 'Option to save the actual media.  The media will automatically saved to the location you specified.
31  
32 'http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL
33 
34 Imports GetMedia.WSDL
35 Imports System.IO
36 
37 
38 Module Module1
39 
40     Sub Main()
41         Dim path As String = "C:\Users\Desktop\image1.jpg"
42 
43         Dim client As WSDL.MessagingClient = New MessagingClient("mms2wsHttpBinding")
44 
45         Dim resp As String = client.GetMedia(New Guid("f01d89fd-5155-5455-5585-e84ab8de8591"), 001)
46 
47         Dim imagetest = Convert.FromBase64String(resp)
48 
49         File.WriteAllBytes(path, imagetest)
50 
51         Console.WriteLine("Image Saved")
52 
53         Console.ReadKey()
54     End Sub
55 
56 End Module
57 
58 
59 'Option to display the actual media.  The media will automatically display when running the code and the image will be saved to the location you specified.
60  
61 'http://messaging.cdyne.com/Messaging.svc?wsdl was added as Service Reference and given the name WSDL
62 
63 Imports GetMedia.WSDL
64 
65 Imports System.IO
66 
67 Module Module1
68 
69     Sub Main()
70 
71         Dim client As WSDL.MessagingClient = New WSDL.MessagingClient("mms2wsHttpBinding")
72 
73         Dim info = client.GetMediaInfo(New WSDL.MediaCriteria() With {
74             .MediaId = 001,
75             .LicenseKey = New Guid("f01d89fd-5155-5455-5585-e84ab8de8591")
76         })
77 
78         Dim content = client.GetMedia(New Guid("f01d89fd-5155-5455-5585-e84ab8de8591"), 001)
79 
80         Dim contentBytes = Convert.FromBase64String(content)
81 
82         Dim filename = $"{System.IO.Path.GetTempFileName()}{info.Media(0).FileName}"
83 
84         File.WriteAllBytes(filename, contentBytes)
85 
86         Dim process = System.Diagnostics.Process.Start(filename)
87 
88     End Sub
89 
90 End Module

PHP with cURL

 1 //The Base64 representation of the image will be printed as the response.
 2 
 3 <?php
 4 
 5 $url='http://messaging.cdyne.com/Messaging.svc/GetMedia?LicenseKey=f01d89fd-5155-5455-5585-e84ab8de8591&MediaID=11777';
 6 $ch = curl_init(); 
 7 
 8 curl_setopt($ch,CURLOPT_URL,$url);
 9 curl_setopt($ch,CURLOPT_HTTPGET,true);
10 curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);  
11 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));
12 
13 $response = curl_exec($ch); 
14 
15 curl_close($ch); 
16 
17 print_r($response);
18 
19 ?>
20 
21 //Option to return the actual media.  The media will automatically saved to the location you specified.
22 
23 <?php
24  
25 $url='http://messaging.cdyne.com/Messaging.svc/GetMedia?LicenseKey=f01d89fd-5155-5455-5585-e84ab8de8591&MediaID=11777';
26 $ch = curl_init(); 
27  
28 curl_setopt($ch,CURLOPT_URL,$url);
29 curl_setopt($ch,CURLOPT_HTTPGET,true);
30 curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);  
31 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));
32  
33 $response = curl_exec($ch);
34  
35 curl_close($ch); 
36  
37 $data = base64_decode($response);
38 $path = 'C:\Users\Desktop\TestImage.jpg';
39 
40 file_put_contents($path, $data);
41 
42 echo "Image Saved to: ", $path;
43 
44 ?>
45 
46 //Option to display the actual media.  The media will automatically display when running the code and the image will be saved to the location you specified.
47  
48 <?php
49  
50 
51 $url='http://messaging.cdyne.com/Messaging.svc/GetMedia?LicenseKey=f01d89fd-5155-5455-5585-e84ab8de8591&MediaID=11777';
52 
53 $ch = curl_init(); 
54  
55 curl_setopt($ch,CURLOPT_URL,$url);
56 curl_setopt($ch,CURLOPT_HTTPGET,true);
57 curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);  
58 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));
59   
60 $response = curl_exec($ch); 
61 
62 curl_close($ch); 
63  
64 $data = base64_decode($response);
65 $path = 'C:\Users\Desktop\TestImage.jpg';
66 
67 file_put_contents($path, $data);
68 
69 echo $data;
70 
71 ?>

VBScript

 1 Dim oXMLHTTP
 2 Set oXMLHTTP = CreateObject("Microsoft.XMLHTTP")
 3 Set oDoc = CreateObject("MSXML2.DOMDocument")
 4 
 5 Call oXMLHttp.Open("GET", "http://messaging.cdyne.com/Messaging.svc/GetMedia?LicenseKey=f01d89fd-5155-5455-5585-e84ab8de8591&MediaId=1366", false)
 6 Call oXMLHttp.setRequestHeader("Content-Type", "text/xml")
 7 Call oXMLHttp.send
 8 
 9 MsgBox oXMLHTTP.responseText
10 
11 Const ForReading = 1, ForWriting = 2, ForAppending = 8
12 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
13 Dim fso, MyFile, FileName, TextLine
14 Set fso = CreateObject("Scripting.FileSystemObject")
15 FileName = "c:\Users\Desktop\MMS.txt"
16 Set MyFile = fso.OpenTextFile(FileName, ForWriting, True)
17 MyFile.WriteLine oXMLHttp.responseText
18 MyFile.Close
19 Set MyFile = fso.OpenTextFile(FileName, ForReading)
20 Do While MyFile.AtEndOfStream <> True
21 TextLine = MyFile.ReadLine
22 Loop
23 
24 MyFile.Close  
25 
26 set request = nothing

JAVA

 1 import java.io.ByteArrayOutputStream;
 2 import java.io.InputStream;
 3 import java.net.MalformedURLException;
 4 import java.net.URL;
 5 import java.util.Properties;
 6 import javax.xml.transform.OutputKeys;
 7 import javax.xml.transform.Source;
 8 import javax.xml.transform.Transformer;
 9 import javax.xml.transform.TransformerFactory;
10 import javax.xml.transform.stream.StreamResult;
11 import javax.xml.transform.stream.StreamSource;
12 
13 public final class GetMedia {
14 
15     public static void main(String[] args) {
16 
17         try {
18             URL url = new URL("http://messaging.cdyne.com/Messaging.svc/GetMedia?"
19                     + "LicenseKey=f01d89fd-5155-5455-5585-e84ab8de8591"
20                     + "&MediaID=11777");
21             try {
22                 InputStream in = url.openStream();
23                 StreamSource source = new StreamSource(in);
24                 printResult(source);
25             } catch (java.io.IOException e) {
26             }
27         } catch (MalformedURLException e) {
28         }
29     }
30 
31     private static void printResult(Source source) {
32         try {
33             ByteArrayOutputStream bos = new ByteArrayOutputStream();
34             StreamResult sr = new StreamResult(bos);
35             Transformer trans = TransformerFactory.newInstance().newTransformer();
36             Properties oprops = new Properties();
37             oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
38             trans.setOutputProperties(oprops);
39             trans.transform(source, sr);
40             System.out.println("**** Response ******");
41             System.out.println(bos.toString());
42 
43             bos.close();
44             System.out.println();
45         } catch (Exception e) {
46         }
47     }
48 }