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
83
84
85
86
87
88
89
|
#ifndef _DROPBOX_API_UPLOAD_H_
#define _DROPBOX_API_UPLOAD_H_
class UploadFileRequest : public HttpRequest
{
public:
UploadFileRequest(const char *token, const char *path, const char *data, size_t size) :
HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/octet-stream");
JSONNode params(JSON_NODE);
params
<< JSONNode("path", path)
<< JSONNode("mode", "overwrite");
AddHeader("Dropbox-API-Arg", params.write().c_str());
SetData(data, size);
}
};
class StartUploadSessionRequest : public HttpRequest
{
public:
StartUploadSessionRequest(const char *token, const char *data, size_t size) :
HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/start")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/octet-stream");
SetData(data, size);
}
};
class AppendToUploadSessionRequest : public HttpRequest
{
public:
AppendToUploadSessionRequest(const char *token, const char *sessionId, size_t offset, const char *data, size_t size) :
HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/append_v2")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/octet-stream");
JSONNode params(JSON_NODE);
params
<< JSONNode("session_id", sessionId)
<< JSONNode("offset", (unsigned long)offset);
AddHeader("Dropbox-API-Arg", params.write().c_str());
SetData(data, size);
}
};
class FinishUploadSessionRequest : public HttpRequest
{
public:
FinishUploadSessionRequest(const char *token, const char *sessionId, size_t offset, const char *path, const char *data, size_t size) :
HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/finish")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/octet-stream");
JSONNode cursor(JSON_NODE);
cursor.set_name("cursor");
cursor
<< JSONNode("session_id", sessionId)
<< JSONNode("offset", (unsigned long)offset);
JSONNode commit(JSON_NODE);
commit.set_name("commit");
commit
<< JSONNode("path", path)
<< JSONNode("mode", "overwrite");
JSONNode params(JSON_NODE);
params
<< cursor
<< commit;
AddHeader("Dropbox-API-Arg", params.write().c_str());
SetData(data, size);
}
};
#endif //_DROPBOX_API_UPLOAD_H_
|