22using QBox . Auth ;
33using QBox . RS ;
44using QBox . FileOp ;
5+ using QBox . RPC ;
56
67namespace QBox . Demo
78{
@@ -10,39 +11,41 @@ public class Demo
1011 public static string bucketName ;
1112 public static string key ;
1213 public static string localFile ;
14+ public static string bigkey ;
15+ public static string bigFile ;
1316 public static string DEMO_DOMAIN ;
1417 public static Client conn ;
1518 public static RSService rs ;
16- public static ImageOp imageOp ;
1719
1820 public static void Main ( )
1921 {
2022 Config . ACCESS_KEY = "<Please apply your access key>" ;
2123 Config . SECRET_KEY = "<Dont send your secret key to anyone>" ;
2224
23- bucketName = "csharpbucket" ;
24- DEMO_DOMAIN = "csharpbucket.dn.qbox.me" ;
25- localFile = "Resource/gogopher.jpg" ;
25+ bucketName = "yourbucket" ;
26+ DEMO_DOMAIN = bucketName + ".qiniudn.com" ;
2627 key = "gogopher.jpg" ;
28+ localFile = "Resource/gogopher.jpg" ;
29+ bigkey = key ;
30+ bigFile = localFile ;
2731
2832 conn = new DigestAuthClient ( ) ;
2933 rs = new RSService ( conn , bucketName ) ;
30- imageOp = new ImageOp ( conn ) ;
3134
3235 MkBucket ( ) ;
3336 RSClientPutFile ( ) ;
34- Get ( ) ;
35- Stat ( ) ;
36- Publish ( ) ;
37- UnPublish ( ) ;
38- Delete ( ) ;
37+ Get ( key ) ;
38+ ResumablePutFile ( ) ;
39+ Stat ( bigkey ) ;
40+ Delete ( key ) ;
3941 Drop ( ) ;
4042
4143 MkBucket ( ) ;
4244 RSPutFile ( ) ;
43- Publish ( ) ;
4445 ImageOps ( ) ;
4546
47+ MakeDownloadToken ( ) ;
48+
4649 Console . ReadLine ( ) ;
4750 }
4851
@@ -70,52 +73,45 @@ public static void RSPutFile()
7073
7174 public static void RSClientPutFile ( )
7275 {
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 ) ;
8580
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>" ) ;
8883 PrintRet ( putFileRet ) ;
8984 if ( putFileRet . OK )
9085 {
9186 Console . WriteLine ( "Hash: " + putFileRet . Hash ) ;
9287 }
9388 else
9489 {
95- Console . WriteLine ( "Failed to RSClient.PutFile " ) ;
90+ Console . WriteLine ( "Failed to RSClient.PutFileWithUpToken " ) ;
9691 }
92+ }
9793
98- Console . WriteLine ( "\n ===> Generate UpToken" ) ;
94+ public static void ResumablePutFile ( )
95+ {
96+ Console . WriteLine ( "\n ===> ResumablePut.PutFile" ) ;
9997 var authPolicy = new AuthPolicy ( bucketName , 3600 ) ;
10098 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>" ) ;
105101 PrintRet ( putFileRet ) ;
106102 if ( putFileRet . OK )
107103 {
108104 Console . WriteLine ( "Hash: " + putFileRet . Hash ) ;
109105 }
110106 else
111107 {
112- Console . WriteLine ( "Failed to RSClient.PutFileWithUpToken " ) ;
108+ Console . WriteLine ( "Failed to ResumablePut.PutFile " ) ;
113109 }
114110 }
115111
116- public static void Get ( )
112+ public static void Get ( string key )
117113 {
118- Console . WriteLine ( "\n ===> Get" ) ;
114+ Console . WriteLine ( "\n ===> RSService. Get" ) ;
119115 GetRet getRet = rs . Get ( key , "attName" ) ;
120116 PrintRet ( getRet ) ;
121117 if ( getRet . OK )
@@ -130,7 +126,7 @@ public static void Get()
130126 Console . WriteLine ( "Failed to Get" ) ;
131127 }
132128
133- Console . WriteLine ( "\n ===> GetIfNotModified" ) ;
129+ Console . WriteLine ( "\n ===> RSService. GetIfNotModified" ) ;
134130 getRet = rs . GetIfNotModified ( key , "attName" , getRet . Hash ) ;
135131 PrintRet ( getRet ) ;
136132 if ( getRet . OK )
@@ -146,9 +142,9 @@ public static void Get()
146142 }
147143 }
148144
149- public static void Stat ( )
145+ public static void Stat ( string key )
150146 {
151- Console . WriteLine ( "\n ===> Stat" ) ;
147+ Console . WriteLine ( "\n ===> RSService. Stat" ) ;
152148 StatRet statRet = rs . Stat ( key ) ;
153149 PrintRet ( statRet ) ;
154150 if ( statRet . OK )
@@ -164,9 +160,9 @@ public static void Stat()
164160 }
165161 }
166162
167- public static void Delete ( )
163+ public static void Delete ( string key )
168164 {
169- Console . WriteLine ( "\n ===> Delete" ) ;
165+ Console . WriteLine ( "\n ===> RSService. Delete" ) ;
170166 CallRet deleteRet = rs . Delete ( key ) ;
171167 PrintRet ( deleteRet ) ;
172168 if ( ! deleteRet . OK )
@@ -177,7 +173,7 @@ public static void Delete()
177173
178174 public static void Drop ( )
179175 {
180- Console . WriteLine ( "\n ===> Drop" ) ;
176+ Console . WriteLine ( "\n ===> RSService. Drop" ) ;
181177 CallRet dropRet = rs . Drop ( ) ;
182178 PrintRet ( dropRet ) ;
183179 if ( ! dropRet . OK )
@@ -186,32 +182,19 @@ public static void Drop()
186182 }
187183 }
188184
189- public static void Publish ( )
185+ public static void MakeDownloadToken ( )
190186 {
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 ) ;
209192 }
210193
211194 public static void ImageOps ( )
212195 {
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 ) ;
215198 PrintRet ( infoRet ) ;
216199 if ( infoRet . OK )
217200 {
@@ -225,34 +208,34 @@ public static void ImageOps()
225208 Console . WriteLine ( "Failed to ImageInfo" ) ;
226209 }
227210
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 ) ;
230213 PrintRet ( exifRet ) ;
231214 if ( ! exifRet . OK )
232215 {
233216 Console . WriteLine ( "Failed to ImageExif" ) ;
234217 }
235218
236- Console . WriteLine ( "\n ===> ImageViewUrl" ) ;
219+ Console . WriteLine ( "\n ===> FileOp. ImageViewUrl" ) ;
237220 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 ) ;
239222 Console . WriteLine ( "ImageViewUrl 1:" + viewUrl ) ;
240223 viewSpec . Quality = 1 ;
241224 viewSpec . Format = "gif" ;
242- viewUrl = imageOp . ImageViewUrl ( "http://" + DEMO_DOMAIN + "/" + key , viewSpec ) ;
225+ viewUrl = ImageOp . ImageViewUrl ( "http://" + DEMO_DOMAIN + "/" + key , viewSpec ) ;
243226 Console . WriteLine ( "ImageViewUrl 2:" + viewUrl ) ;
244227 viewSpec . Quality = 90 ;
245228 viewSpec . Sharpen = 10 ;
246229 viewSpec . Format = "png" ;
247- viewUrl = imageOp . ImageViewUrl ( "http://" + DEMO_DOMAIN + "/" + key , viewSpec ) ;
230+ viewUrl = ImageOp . ImageViewUrl ( "http://" + DEMO_DOMAIN + "/" + key , viewSpec ) ;
248231 Console . WriteLine ( "ImageViewUrl 3:" + viewUrl ) ;
249232
250- Console . WriteLine ( "\n ===> ImageMogrifyUrl" ) ;
233+ Console . WriteLine ( "\n ===> FileOp. ImageMogrifyUrl" ) ;
251234 ImageMogrifySpec mogrSpec = new ImageMogrifySpec {
252235 Thumbnail = "!50x50r" , Gravity = "center" , Rotate = 90 ,
253236 Crop = "!50x50" , Quality = 80 , AutoOrient = true
254237 } ;
255- string mogrUrl = imageOp . ImageMogrifyUrl ( "http://" + DEMO_DOMAIN + "/" + key , mogrSpec ) ;
238+ string mogrUrl = ImageOp . ImageMogrifyUrl ( "http://" + DEMO_DOMAIN + "/" + key , mogrSpec ) ;
256239 Console . WriteLine ( "ImageMogrifyUrl:" + mogrUrl ) ;
257240
258241 Console . WriteLine ( "\n ===> Get" ) ;
@@ -269,7 +252,7 @@ public static void ImageOps()
269252 {
270253 Console . WriteLine ( "Failed to Get" ) ;
271254 }
272- Console . WriteLine ( "\n ===> ImageMogrifySaveAs" ) ;
255+ Console . WriteLine ( "\n ===> FileOp. ImageMogrifySaveAs" ) ;
273256 PutFileRet saveAsRet = rs . ImageMogrifySaveAs ( getRet . Url , mogrSpec , key + ".mogr-save-as" ) ;
274257 PrintRet ( saveAsRet ) ;
275258 if ( saveAsRet . OK )
0 commit comments