Skip to content

Commit 45319cc

Browse files
committed
Merge pull request #87 from clouddxy/master
add some demos
2 parents c6864e4 + 7a09b60 commit 45319cc

File tree

10 files changed

+488
-0
lines changed

10 files changed

+488
-0
lines changed

examples/copy.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Qiniu.RS;
7+
using Qiniu.RPC;
8+
9+
namespace ConsoleDemo
10+
{
11+
class BucketManager
12+
{
13+
14+
public static void Copy(string bucketSrc, string keySrc, string bucketDest, string keyDest)
15+
{
16+
//实例化一个RSClient对象,用于操作BucketManager里面的方法
17+
RSClient client = new RSClient();
18+
CallRet ret = client.Copy(new EntryPathPair(bucketSrc, keySrc, bucketDest, keyDest));
19+
if (ret.OK)
20+
{
21+
Console.WriteLine("Copy OK");
22+
}
23+
else
24+
{
25+
Console.WriteLine("Failed to Copy");
26+
}
27+
}
28+
29+
static void Main(string[] args)
30+
{
31+
//初始化AK,SK
32+
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
33+
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
34+
//要测试的空间和key,并且这个key在你空间中存在
35+
String bucket = "Bucket_Name";
36+
String key = "Bucket_key";
37+
38+
//将文件从文件key复制到文件key2, 可以在不同bucket移动
39+
String key2 = "yourjavakey";
40+
//调用Move方法
41+
BucketManager.Stat(bucket,key,bucket,key2);
42+
43+
}
44+
}
45+
}

examples/delete.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Qiniu.RS;
7+
using Qiniu.RPC;
8+
9+
namespace ConsoleDemo
10+
{
11+
class BucketManager
12+
{
13+
14+
15+
public static void Delete(string bucket, string key)
16+
{
17+
//实例化一个RSClient对象,用于操作BucketManager里面的方法
18+
RSClient client = new RSClient();
19+
CallRet ret = client.Delete(new EntryPath(bucket, key));
20+
if (ret.OK)
21+
{
22+
Console.WriteLine("Delete OK");
23+
}
24+
else
25+
{
26+
Console.WriteLine("Failed to delete");
27+
}
28+
}
29+
30+
static void Main(string[] args)
31+
{
32+
//初始化AK,SK
33+
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
34+
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
35+
//要测试的空间和key,并且这个key在你空间中存在
36+
String bucket = "Bucket_Name";
37+
String key = "Bucket_key";
38+
//调用Delete方法
39+
BucketManager.Delete(bucket,key);
40+
41+
}
42+
}
43+
}

examples/download.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Qiniu.RS;
7+
8+
namespace ConsoleDemo
9+
{
10+
class Download
11+
{
12+
public static void download()
13+
{
14+
//设置需要操作的账号的AK和SK
15+
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
16+
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
17+
//构造私有空间的需要生成的下载的链接
18+
string baseUrl = "http://bucketdomain/key";
19+
//调用MakeRequest方法生成私有下载链接
20+
string private_url = GetPolicy.MakeRequest(baseUrl);
21+
Console.WriteLine(private_url);
22+
Console.ReadLine();
23+
}
24+
25+
static void Main(string[] args)
26+
{
27+
Download.download();
28+
}
29+
}
30+
}

examples/fops.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Qiniu.RS;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace ConsoleDemo
9+
{
10+
class Pfop
11+
{
12+
13+
static void Main(string[] args)
14+
{
15+
//初始化AK,SK
16+
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
17+
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
18+
19+
//设置要转码的空间和key,并且这个key在你空间中存在
20+
String bucket = "Bucket_Name";
21+
String key = "Bucket_key";
22+
23+
//实例化一个entry对象
24+
EntryPath entry = new EntryPath(bucket, key);
25+
26+
//设置转码操作参数
27+
String fops = "avthumb/mp4/s/640x360/vb/1.25m";
28+
//设置转码的队列
29+
String pipeline = "yourpipelinename";
30+
31+
//可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当前空间。
32+
String urlbase64 = Qiniu.Util.Base64URLSafe.Encode("保存的空间:保存的key");
33+
String pfops = fops + "|saveas/"+urlbase64;
34+
35+
//实例化一个fop对象主要进行后续转码操作
36+
Qiniu.RS.Pfop fop = new Qiniu.RS.Pfop();
37+
38+
Uri uri = null;
39+
40+
string s = fop.Do(entry, pfops, uri, pipeline, 1);
41+
Console.WriteLine(s);
42+
Console.ReadLine();
43+
}
44+
45+
46+
}
47+
}

examples/move.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Qiniu.RS;
7+
using Qiniu.RPC;
8+
9+
namespace ConsoleDemo
10+
{
11+
class BucketManager
12+
{
13+
14+
public static void Move(string bucketSrc, string keySrc, string bucketDest, string keyDest)
15+
{
16+
17+
//实例化一个RSClient对象,用于操作BucketManager里面的方法
18+
RSClient client = new RSClient();
19+
new EntryPathPair(bucketSrc, keySrc, bucketDest, keyDest);
20+
CallRet ret = client.Move(new EntryPathPair(bucketSrc, keySrc, bucketDest, keyDest));
21+
if (ret.OK)
22+
{
23+
Console.WriteLine("Move OK");
24+
}
25+
else
26+
{
27+
Console.WriteLine("Failed to Move");
28+
}
29+
}
30+
31+
static void Main(string[] args)
32+
{
33+
//初始化AK,SK
34+
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
35+
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
36+
//要测试的空间和key,并且这个key在你空间中存在
37+
String bucket = "Bucket_Name";
38+
String key = "Bucket_key";
39+
40+
//将文件从文件key移动到文件key2, 可以在不同bucket移动,同空间移动相当于重命名
41+
String key2 = "yourjavakey";
42+
//调用Move方法
43+
BucketManager.Move(bucket,key, bucket,key2);
44+
45+
}
46+
}
47+
}

examples/stat.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Qiniu.RS;
7+
using Qiniu.RPC;
8+
9+
namespace ConsoleDemo
10+
{
11+
class BucketManager
12+
{
13+
14+
public static void Stat(string bucket, string key)
15+
{
16+
17+
//实例化一个RSClient对象,用于操作BucketManager里面的方法
18+
RSClient client = new RSClient();
19+
//调用Stat方法获取文件的信息
20+
Entry entry = client.Stat(new EntryPath(bucket, key));
21+
if (entry.OK)
22+
{
23+
//打印文件的hash、fsize等信息
24+
Console.WriteLine("Hash: " + entry.Hash);
25+
Console.WriteLine("Fsize: " + entry.Fsize);
26+
Console.WriteLine("PutTime: " + entry.PutTime);
27+
Console.WriteLine("MimeType: " + entry.MimeType);
28+
Console.ReadLine();
29+
}
30+
else
31+
{
32+
Console.WriteLine("Failed to Stat");
33+
}
34+
}
35+
36+
static void Main(string[] args)
37+
{
38+
//初始化AK,SK
39+
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
40+
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
41+
//要测试的空间和key,并且这个key在你空间中存在
42+
String bucket = "Bucket_Name";
43+
String key = "Bucket_key";
44+
//调用Stat方法
45+
BucketManager.Stat(bucket,key);
46+
47+
}
48+
}
49+
}

examples/upload.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Qiniu.Auth;
7+
using Qiniu.IO;
8+
using Qiniu.IO.Resumable;
9+
using Qiniu.RS;
10+
11+
namespace ConsoleDemo
12+
{
13+
class UploadDemo
14+
{
15+
16+
private void upload()
17+
{
18+
//设置账号的AK和SK
19+
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
20+
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
21+
IOClient target = new IOClient();
22+
PutExtra extra = new PutExtra();
23+
//设置上传的空间
24+
String bucket = "bucket_name";
25+
//设置上传的文件的key值
26+
String key = "yourdefinekey";
27+
28+
//普通上传,只需要设置上传的空间名就可以了,第二个参数可以设定token过期时间
29+
PutPolicy put = new PutPolicy(bucket, 3600);
30+
31+
//调用Token()方法生成上传的Token
32+
string upToken = put.Token();
33+
//上传文件的路径
34+
String filePath = "/.../...";
35+
36+
//调用PutFile()方法上传
37+
PutRet ret = target.PutFile(upToken, key, filePath, extra);
38+
//打印出相应的信息
39+
Console.WriteLine(ret.Response.ToString());
40+
Console.WriteLine(ret.key);
41+
Console.ReadLine();
42+
}
43+
44+
static void Main(string[] args)
45+
{
46+
//实例化UploadDemo对象并调用设置的upload方法
47+
UploadDemo Upload = new UploadDemo();
48+
Upload.upload();
49+
}
50+
51+
}
52+
}

examples/upload_callback.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Qiniu.Auth;
7+
using Qiniu.IO;
8+
using Qiniu.IO.Resumable;
9+
using Qiniu.RS;
10+
11+
namespace ConsoleDemo
12+
{
13+
class UploadDemo
14+
{
15+
16+
private void upload()
17+
{
18+
//设置账号的AK和SK
19+
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
20+
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
21+
IOClient target = new IOClient();
22+
PutExtra extra = new PutExtra();
23+
//设置上传的空间
24+
String bucket = "bucket_name";
25+
//设置上传的文件的key值
26+
String key = "yourdefinekey";
27+
28+
//普通上传,只需要设置上传的空间名就可以了,第二个参数可以设定token过期时间
29+
PutPolicy put = new PutPolicy(bucket, 3600);
30+
31+
//设置callbackUrl以及callbackBody,七牛将文件名和文件大小回调给业务服务器
32+
put.CallBackUrl = "http://your.domain.com/callback";
33+
put.CallBackBody = "filename=$(fname)&filesize=$(fsize)";
34+
35+
//调用Token()方法生成上传的Token
36+
string upToken = put.Token();
37+
//上传文件的路径
38+
String filePath = "/.../...";
39+
40+
PutRet ret = target.PutFile(upToken, key, filePath, extra);
41+
//打印出相应的信息
42+
Console.WriteLine(ret.Response.ToString());
43+
Console.WriteLine(ret.key);
44+
Console.ReadLine();
45+
}
46+
47+
static void Main(string[] args)
48+
{
49+
//实例化UploadDemo对象并调用设置的upload方法
50+
UploadDemo Upload = new UploadDemo();
51+
Upload.upload();
52+
}
53+
54+
}
55+
}

0 commit comments

Comments
 (0)