-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cs
More file actions
54 lines (47 loc) · 1.55 KB
/
example.cs
File metadata and controls
54 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Mime;
using OnlineConvert;
namespace Example
{
public class Example
{
static void Main(String[] args)
{
OnlineConvert.OnlineConvert oc = OnlineConvert.OnlineConvert.create("YOUR API KEY HERE",true,"convert-to-png");
var a = oc.convert("convert-to-png", "URL", "http://upload.wikimedia.org/wikipedia/commons/thumb/9/90/Colonial_Williamsburg_%283205781804%29.jpg/100px-Colonial_Williamsburg_%283205781804%29.jpg", "a.png");
var dica = oc.getXml2Dic(a);
var directDownloadURL = "";
Dictionary<int, Dictionary<string, string>> dicb = new Dictionary<int, Dictionary<string, string>>();
if (dica[1].ContainsKey("hash") && dica[1]["hash"] != "")
{
while (true)
{
var b = oc.getProgress(dica[1]["hash"]);
dicb = oc.getXml2Dic(b);
if (dicb[2].ContainsKey("code") && dicb[2]["code"] == "100")
{
break;
}
System.Threading.Thread.Sleep(5000);
}
directDownloadURL = dicb[1]["directDownload"];
}
if (directDownloadURL != "")
{
using (WebClient Client = new WebClient ())
{
var webClient = new WebClient();
webClient.OpenRead(directDownloadURL);
string header_contentDisposition = webClient.ResponseHeaders["content-disposition"];
string filename = new ContentDisposition(header_contentDisposition).FileName;
filename = filename.Replace("\"", "");
webClient.DownloadFile(directDownloadURL, filename);
}
}
}
}
}