2
2
using QBox . Auth ;
3
3
using QBox . RS ;
4
4
using QBox . FileOp ;
5
+ using QBox . RPC ;
5
6
6
7
namespace QBox . Demo
7
8
{
@@ -10,39 +11,41 @@ public class Demo
10
11
public static string bucketName ;
11
12
public static string key ;
12
13
public static string localFile ;
14
+ public static string bigkey ;
15
+ public static string bigFile ;
13
16
public static string DEMO_DOMAIN ;
14
17
public static Client conn ;
15
18
public static RSService rs ;
16
- public static ImageOp imageOp ;
17
19
18
20
public static void Main ( )
19
21
{
20
22
Config . ACCESS_KEY = "<Please apply your access key>" ;
21
23
Config . SECRET_KEY = "<Dont send your secret key to anyone>" ;
22
24
23
- bucketName = "csharpbucket" ;
24
- DEMO_DOMAIN = "csharpbucket.dn.qbox.me" ;
25
- localFile = "Resource/gogopher.jpg" ;
25
+ bucketName = "yourbucket" ;
26
+ DEMO_DOMAIN = bucketName + ".qiniudn.com" ;
26
27
key = "gogopher.jpg" ;
28
+ localFile = "Resource/gogopher.jpg" ;
29
+ bigkey = key ;
30
+ bigFile = localFile ;
27
31
28
32
conn = new DigestAuthClient ( ) ;
29
33
rs = new RSService ( conn , bucketName ) ;
30
- imageOp = new ImageOp ( conn ) ;
31
34
32
35
MkBucket ( ) ;
33
36
RSClientPutFile ( ) ;
34
- Get ( ) ;
35
- Stat ( ) ;
36
- Publish ( ) ;
37
- UnPublish ( ) ;
38
- Delete ( ) ;
37
+ Get ( key ) ;
38
+ ResumablePutFile ( ) ;
39
+ Stat ( bigkey ) ;
40
+ Delete ( key ) ;
39
41
Drop ( ) ;
40
42
41
43
MkBucket ( ) ;
42
44
RSPutFile ( ) ;
43
- Publish ( ) ;
44
45
ImageOps ( ) ;
45
46
47
+ MakeDownloadToken ( ) ;
48
+
46
49
Console . ReadLine ( ) ;
47
50
}
48
51
@@ -70,52 +73,45 @@ public static void RSPutFile()
70
73
71
74
public static void RSClientPutFile ( )
72
75
{
73
- Console . WriteLine ( "\n ==> PutAuth" ) ;
74
- PutAuthRet putAuthRet = rs . PutAuth ( ) ;
75
- PrintRet ( putAuthRet ) ;
76
- if ( putAuthRet . OK )
77
- {
78
- Console . WriteLine ( "Expires: " + putAuthRet . Expires . ToString ( ) ) ;
79
- Console . WriteLine ( "Url: " + putAuthRet . Url ) ;
80
- }
81
- else
82
- {
83
- Console . WriteLine ( "Failed to PutAuth" ) ;
84
- }
76
+ Console . WriteLine ( "\n ===> RSClient Generate UpToken" ) ;
77
+ var authPolicy = new AuthPolicy ( bucketName , 3600 ) ;
78
+ string upToken = authPolicy . MakeAuthTokenString ( ) ;
79
+ Console . WriteLine ( "upToken: " + upToken ) ;
85
80
86
- Console . WriteLine ( "\n ===> RSClient.PutFile " ) ;
87
- PutFileRet putFileRet = RSClient . PutFile ( putAuthRet . Url , bucketName , key , null , localFile , null , "key=<key>" ) ;
81
+ Console . WriteLine ( "\n ===> RSClient.PutFileWithUpToken " ) ;
82
+ PutFileRet putFileRet = RSClient . PutFileWithUpToken ( upToken , bucketName , key , null , localFile , null , "key=<key>" ) ;
88
83
PrintRet ( putFileRet ) ;
89
84
if ( putFileRet . OK )
90
85
{
91
86
Console . WriteLine ( "Hash: " + putFileRet . Hash ) ;
92
87
}
93
88
else
94
89
{
95
- Console . WriteLine ( "Failed to RSClient.PutFile " ) ;
90
+ Console . WriteLine ( "Failed to RSClient.PutFileWithUpToken " ) ;
96
91
}
92
+ }
97
93
98
- Console . WriteLine ( "\n ===> Generate UpToken" ) ;
94
+ public static void ResumablePutFile ( )
95
+ {
96
+ Console . WriteLine ( "\n ===> ResumablePut.PutFile" ) ;
99
97
var authPolicy = new AuthPolicy ( bucketName , 3600 ) ;
100
98
string upToken = authPolicy . MakeAuthTokenString ( ) ;
101
- Console . WriteLine ( "upToken: " + upToken ) ;
102
-
103
- Console . WriteLine ( "\n ===> RSClient.PutFileWithUpToken" ) ;
104
- putFileRet = RSClient . PutFileWithUpToken ( upToken , bucketName , key , null , localFile , null , "key=<key>" ) ;
99
+ PutAuthClient client = new PutAuthClient ( upToken ) ;
100
+ PutFileRet putFileRet = ResumablePut . PutFile ( client , bucketName , bigkey , null , bigFile , null , "key=<key>" ) ;
105
101
PrintRet ( putFileRet ) ;
106
102
if ( putFileRet . OK )
107
103
{
108
104
Console . WriteLine ( "Hash: " + putFileRet . Hash ) ;
109
105
}
110
106
else
111
107
{
112
- Console . WriteLine ( "Failed to RSClient.PutFileWithUpToken " ) ;
108
+ Console . WriteLine ( "Failed to ResumablePut.PutFile " ) ;
113
109
}
114
110
}
115
111
116
- public static void Get ( )
112
+ public static void Get ( string key )
117
113
{
118
- Console . WriteLine ( "\n ===> Get" ) ;
114
+ Console . WriteLine ( "\n ===> RSService. Get" ) ;
119
115
GetRet getRet = rs . Get ( key , "attName" ) ;
120
116
PrintRet ( getRet ) ;
121
117
if ( getRet . OK )
@@ -130,7 +126,7 @@ public static void Get()
130
126
Console . WriteLine ( "Failed to Get" ) ;
131
127
}
132
128
133
- Console . WriteLine ( "\n ===> GetIfNotModified" ) ;
129
+ Console . WriteLine ( "\n ===> RSService. GetIfNotModified" ) ;
134
130
getRet = rs . GetIfNotModified ( key , "attName" , getRet . Hash ) ;
135
131
PrintRet ( getRet ) ;
136
132
if ( getRet . OK )
@@ -146,9 +142,9 @@ public static void Get()
146
142
}
147
143
}
148
144
149
- public static void Stat ( )
145
+ public static void Stat ( string key )
150
146
{
151
- Console . WriteLine ( "\n ===> Stat" ) ;
147
+ Console . WriteLine ( "\n ===> RSService. Stat" ) ;
152
148
StatRet statRet = rs . Stat ( key ) ;
153
149
PrintRet ( statRet ) ;
154
150
if ( statRet . OK )
@@ -164,9 +160,9 @@ public static void Stat()
164
160
}
165
161
}
166
162
167
- public static void Delete ( )
163
+ public static void Delete ( string key )
168
164
{
169
- Console . WriteLine ( "\n ===> Delete" ) ;
165
+ Console . WriteLine ( "\n ===> RSService. Delete" ) ;
170
166
CallRet deleteRet = rs . Delete ( key ) ;
171
167
PrintRet ( deleteRet ) ;
172
168
if ( ! deleteRet . OK )
@@ -177,7 +173,7 @@ public static void Delete()
177
173
178
174
public static void Drop ( )
179
175
{
180
- Console . WriteLine ( "\n ===> Drop" ) ;
176
+ Console . WriteLine ( "\n ===> RSService. Drop" ) ;
181
177
CallRet dropRet = rs . Drop ( ) ;
182
178
PrintRet ( dropRet ) ;
183
179
if ( ! dropRet . OK )
@@ -186,32 +182,19 @@ public static void Drop()
186
182
}
187
183
}
188
184
189
- public static void Publish ( )
185
+ public static void MakeDownloadToken ( )
190
186
{
191
- Console . WriteLine ( "\n ===> Publish" ) ;
192
- CallRet publishRet = rs . Publish ( DEMO_DOMAIN ) ;
193
- PrintRet ( publishRet ) ;
194
- if ( ! publishRet . OK )
195
- {
196
- Console . WriteLine ( "Failed to Publish" ) ;
197
- }
198
- }
199
-
200
- public static void UnPublish ( )
201
- {
202
- Console . WriteLine ( "\n ===> UnPublish" ) ;
203
- CallRet publishRet = rs . Unpublish ( DEMO_DOMAIN ) ;
204
- PrintRet ( publishRet ) ;
205
- if ( ! publishRet . OK )
206
- {
207
- Console . WriteLine ( "Failed to UnPublish" ) ;
208
- }
187
+ Console . WriteLine ( "\n ===> Auth.MakeDownloadToken" ) ;
188
+ string pattern = "*/*" ;
189
+ var downloadPolicy = new DownloadPolicy ( pattern , 3600 ) ;
190
+ string dnToken = downloadPolicy . MakeAuthTokenString ( ) ;
191
+ Console . WriteLine ( "dnToken: " + dnToken ) ;
209
192
}
210
193
211
194
public static void ImageOps ( )
212
195
{
213
- Console . WriteLine ( "\n ===> ImageInfo" ) ;
214
- ImageInfoRet infoRet = imageOp . ImageInfo ( "http://" + DEMO_DOMAIN + "/" + key ) ;
196
+ Console . WriteLine ( "\n ===> FileOp. ImageInfo" ) ;
197
+ ImageInfoRet infoRet = ImageOp . ImageInfo ( "http://" + DEMO_DOMAIN + "/" + key ) ;
215
198
PrintRet ( infoRet ) ;
216
199
if ( infoRet . OK )
217
200
{
@@ -225,34 +208,34 @@ public static void ImageOps()
225
208
Console . WriteLine ( "Failed to ImageInfo" ) ;
226
209
}
227
210
228
- Console . WriteLine ( "\n ===> ImageExif" ) ;
229
- CallRet exifRet = imageOp . ImageExif ( "http://" + DEMO_DOMAIN + "/" + key ) ;
211
+ Console . WriteLine ( "\n ===> FileOp. ImageExif" ) ;
212
+ CallRet exifRet = ImageOp . ImageExif ( "http://" + DEMO_DOMAIN + "/" + key ) ;
230
213
PrintRet ( exifRet ) ;
231
214
if ( ! exifRet . OK )
232
215
{
233
216
Console . WriteLine ( "Failed to ImageExif" ) ;
234
217
}
235
218
236
- Console . WriteLine ( "\n ===> ImageViewUrl" ) ;
219
+ Console . WriteLine ( "\n ===> FileOp. ImageViewUrl" ) ;
237
220
ImageViewSpec viewSpec = new ImageViewSpec { Mode = 0 , Width = 200 , Height = 200 } ;
238
- string viewUrl = imageOp . ImageViewUrl ( "http://" + DEMO_DOMAIN + "/" + key , viewSpec ) ;
221
+ string viewUrl = ImageOp . ImageViewUrl ( "http://" + DEMO_DOMAIN + "/" + key , viewSpec ) ;
239
222
Console . WriteLine ( "ImageViewUrl 1:" + viewUrl ) ;
240
223
viewSpec . Quality = 1 ;
241
224
viewSpec . Format = "gif" ;
242
- viewUrl = imageOp . ImageViewUrl ( "http://" + DEMO_DOMAIN + "/" + key , viewSpec ) ;
225
+ viewUrl = ImageOp . ImageViewUrl ( "http://" + DEMO_DOMAIN + "/" + key , viewSpec ) ;
243
226
Console . WriteLine ( "ImageViewUrl 2:" + viewUrl ) ;
244
227
viewSpec . Quality = 90 ;
245
228
viewSpec . Sharpen = 10 ;
246
229
viewSpec . Format = "png" ;
247
- viewUrl = imageOp . ImageViewUrl ( "http://" + DEMO_DOMAIN + "/" + key , viewSpec ) ;
230
+ viewUrl = ImageOp . ImageViewUrl ( "http://" + DEMO_DOMAIN + "/" + key , viewSpec ) ;
248
231
Console . WriteLine ( "ImageViewUrl 3:" + viewUrl ) ;
249
232
250
- Console . WriteLine ( "\n ===> ImageMogrifyUrl" ) ;
233
+ Console . WriteLine ( "\n ===> FileOp. ImageMogrifyUrl" ) ;
251
234
ImageMogrifySpec mogrSpec = new ImageMogrifySpec {
252
235
Thumbnail = "!50x50r" , Gravity = "center" , Rotate = 90 ,
253
236
Crop = "!50x50" , Quality = 80 , AutoOrient = true
254
237
} ;
255
- string mogrUrl = imageOp . ImageMogrifyUrl ( "http://" + DEMO_DOMAIN + "/" + key , mogrSpec ) ;
238
+ string mogrUrl = ImageOp . ImageMogrifyUrl ( "http://" + DEMO_DOMAIN + "/" + key , mogrSpec ) ;
256
239
Console . WriteLine ( "ImageMogrifyUrl:" + mogrUrl ) ;
257
240
258
241
Console . WriteLine ( "\n ===> Get" ) ;
@@ -269,7 +252,7 @@ public static void ImageOps()
269
252
{
270
253
Console . WriteLine ( "Failed to Get" ) ;
271
254
}
272
- Console . WriteLine ( "\n ===> ImageMogrifySaveAs" ) ;
255
+ Console . WriteLine ( "\n ===> FileOp. ImageMogrifySaveAs" ) ;
273
256
PutFileRet saveAsRet = rs . ImageMogrifySaveAs ( getRet . Url , mogrSpec , key + ".mogr-save-as" ) ;
274
257
PrintRet ( saveAsRet ) ;
275
258
if ( saveAsRet . OK )
0 commit comments