-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageshack.cpp
82 lines (63 loc) · 1.91 KB
/
Imageshack.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "stdafx.h"
#include "Imageshack.h"
Imageshack::Imageshack()
{
this->m_Address = "www.imageshack.us";
this->m_Port = 80;
this->m_Target = "/upload_api.php";
this->m_ContentType = "multipart/form-data, boundary=BO--UN--DA--RY----FI--LE";
this->m_PostData = "--BO--UN--DA--RY----FI--LE\r\n";
this->m_PostData += "Content-Disposition: form-data; name=\"key\"\r\n\r\n" + std::string(IMAGESHACK_API_KEY) + std::string("\r\n");
this->m_PostData += "--BO--UN--DA--RY----FI--LE\r\n";
this->m_PostData += "Content-Disposition: form-data; name=\"uploadtype\"\r\n\r\n";
this->m_PostData += "on\r\n";
this->m_PostData += "--BO--UN--DA--RY----FI--LE\r\n";
}
std::string Imageshack::Upload(std::string fileName, unsigned char Type)
{
std::stringstream file_upload;
file_upload << "Content-Disposition: form-data; name=\"fileupload\"; ";
switch(Type)
{
case FILE_JPEG:
file_upload << "filename=\"upload.jpg\"\r\n";
file_upload << "Content-Type: image/jpeg\r\n\r\n";
break;
case FILE_PNG:
file_upload << "filename=\"upload.png\"\r\n";
file_upload << "Content-Type: image/png\r\n\r\n";
break;
case FILE_GIF:
file_upload << "filename=\"upload.gif\"\r\n";
file_upload << "Content-Type: image/gif\r\n\r\n";
break;
case FILE_BMP:
file_upload << "filename=\"upload.bmp\"\r\n";
file_upload << "Content-Type: image/bmp\r\n\r\n";
break;
}
/*
/ Read image from disk.
*/
file_upload << LoadFileFromDisk(fileName);
file_upload << "\r\n";
file_upload << "--BO--UN--DA--RY----FI--LE--\r\n";
/*
/ Final m_Packet assembling.
*/
this->m_PostData += file_upload.str();
std::string link = HttpClient::Upload();
return link;
}
std::string Imageshack::ParseResult(char *Buffer)
{
std::string link = Buffer;
size_t pos, pos2;
pos = link.find("<image_link>") + strlen("<image_link>");
pos2 = link.find("</image_link>");
link = link.substr(pos, pos2-pos);
return link;
}
Imageshack::~Imageshack()
{
}