Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions examples/copy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Qiniu.RS;
using Qiniu.RPC;

namespace ConsoleDemo
{
class BucketManager
{

public static void Copy(string bucketSrc, string keySrc, string bucketDest, string keyDest)
{
//实例化一个RSClient对象,用于操作BucketManager里面的方法
RSClient client = new RSClient();
CallRet ret = client.Copy(new EntryPathPair(bucketSrc, keySrc, bucketDest, keyDest));
if (ret.OK)
{
Console.WriteLine("Copy OK");
}
else
{
Console.WriteLine("Failed to Copy");
}
}

static void Main(string[] args)
{
//初始化AK,SK
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
//要测试的空间和key,并且这个key在你空间中存在
String bucket = "Bucket_Name";
String key = "Bucket_key";

//将文件从文件key复制到文件key2, 可以在不同bucket移动
String key2 = "yourjavakey";
//调用Move方法
BucketManager.Stat(bucket,key,bucket,key2);

}
}
}
43 changes: 43 additions & 0 deletions examples/delete.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Qiniu.RS;
using Qiniu.RPC;

namespace ConsoleDemo
{
class BucketManager
{


public static void Delete(string bucket, string key)
{
//实例化一个RSClient对象,用于操作BucketManager里面的方法
RSClient client = new RSClient();
CallRet ret = client.Delete(new EntryPath(bucket, key));
if (ret.OK)
{
Console.WriteLine("Delete OK");
}
else
{
Console.WriteLine("Failed to delete");
}
}

static void Main(string[] args)
{
//初始化AK,SK
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
//要测试的空间和key,并且这个key在你空间中存在
String bucket = "Bucket_Name";
String key = "Bucket_key";
//调用Delete方法
BucketManager.Delete(bucket,key);

}
}
}
30 changes: 30 additions & 0 deletions examples/download.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Qiniu.RS;

namespace ConsoleDemo
{
class Download
{
public static void download()
{
//设置需要操作的账号的AK和SK
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
//构造私有空间的需要生成的下载的链接
string baseUrl = "http://bucketdomain/key";
//调用MakeRequest方法生成私有下载链接
string private_url = GetPolicy.MakeRequest(baseUrl);
Console.WriteLine(private_url);
Console.ReadLine();
}

static void Main(string[] args)
{
Download.download();
}
}
}
47 changes: 47 additions & 0 deletions examples/fops.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Qiniu.RS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleDemo
{
class Pfop
{

static void Main(string[] args)
{
//初始化AK,SK
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";

//设置要转码的空间和key,并且这个key在你空间中存在
String bucket = "Bucket_Name";
String key = "Bucket_key";

//实例化一个entry对象
EntryPath entry = new EntryPath(bucket, key);

//设置转码操作参数
String fops = "avthumb/mp4/s/640x360/vb/1.25m";
//设置转码的队列
String pipeline = "yourpipelinename";

//可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当前空间。
String urlbase64 = Qiniu.Util.Base64URLSafe.Encode("保存的空间:保存的key");
String pfops = fops + "|saveas/"+urlbase64;

//实例化一个fop对象主要进行后续转码操作
Qiniu.RS.Pfop fop = new Qiniu.RS.Pfop();

Uri uri = null;

string s = fop.Do(entry, pfops, uri, pipeline, 1);
Console.WriteLine(s);
Console.ReadLine();
}


}
}
47 changes: 47 additions & 0 deletions examples/move.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Qiniu.RS;
using Qiniu.RPC;

namespace ConsoleDemo
{
class BucketManager
{

public static void Move(string bucketSrc, string keySrc, string bucketDest, string keyDest)
{

//实例化一个RSClient对象,用于操作BucketManager里面的方法
RSClient client = new RSClient();
new EntryPathPair(bucketSrc, keySrc, bucketDest, keyDest);
CallRet ret = client.Move(new EntryPathPair(bucketSrc, keySrc, bucketDest, keyDest));
if (ret.OK)
{
Console.WriteLine("Move OK");
}
else
{
Console.WriteLine("Failed to Move");
}
}

static void Main(string[] args)
{
//初始化AK,SK
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
//要测试的空间和key,并且这个key在你空间中存在
String bucket = "Bucket_Name";
String key = "Bucket_key";

//将文件从文件key移动到文件key2, 可以在不同bucket移动,同空间移动相当于重命名
String key2 = "yourjavakey";
//调用Move方法
BucketManager.Move(bucket,key, bucket,key2);

}
}
}
49 changes: 49 additions & 0 deletions examples/stat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Qiniu.RS;
using Qiniu.RPC;

namespace ConsoleDemo
{
class BucketManager
{

public static void Stat(string bucket, string key)
{

//实例化一个RSClient对象,用于操作BucketManager里面的方法
RSClient client = new RSClient();
//调用Stat方法获取文件的信息
Entry entry = client.Stat(new EntryPath(bucket, key));
if (entry.OK)
{
//打印文件的hash、fsize等信息
Console.WriteLine("Hash: " + entry.Hash);
Console.WriteLine("Fsize: " + entry.Fsize);
Console.WriteLine("PutTime: " + entry.PutTime);
Console.WriteLine("MimeType: " + entry.MimeType);
Console.ReadLine();
}
else
{
Console.WriteLine("Failed to Stat");
}
}

static void Main(string[] args)
{
//初始化AK,SK
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
//要测试的空间和key,并且这个key在你空间中存在
String bucket = "Bucket_Name";
String key = "Bucket_key";
//调用Stat方法
BucketManager.Stat(bucket,key);

}
}
}
52 changes: 52 additions & 0 deletions examples/upload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Qiniu.Auth;
using Qiniu.IO;
using Qiniu.IO.Resumable;
using Qiniu.RS;

namespace ConsoleDemo
{
class UploadDemo
{

private void upload()
{
//设置账号的AK和SK
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
IOClient target = new IOClient();
PutExtra extra = new PutExtra();
//设置上传的空间
String bucket = "bucket_name";
//设置上传的文件的key值
String key = "yourdefinekey";

//普通上传,只需要设置上传的空间名就可以了,第二个参数可以设定token过期时间
PutPolicy put = new PutPolicy(bucket, 3600);

//调用Token()方法生成上传的Token
string upToken = put.Token();
//上传文件的路径
String filePath = "/.../...";

//调用PutFile()方法上传
PutRet ret = target.PutFile(upToken, key, filePath, extra);
//打印出相应的信息
Console.WriteLine(ret.Response.ToString());
Console.WriteLine(ret.key);
Console.ReadLine();
}

static void Main(string[] args)
{
//实例化UploadDemo对象并调用设置的upload方法
UploadDemo Upload = new UploadDemo();
Upload.upload();
}

}
}
55 changes: 55 additions & 0 deletions examples/upload_callback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Qiniu.Auth;
using Qiniu.IO;
using Qiniu.IO.Resumable;
using Qiniu.RS;

namespace ConsoleDemo
{
class UploadDemo
{

private void upload()
{
//设置账号的AK和SK
Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";
IOClient target = new IOClient();
PutExtra extra = new PutExtra();
//设置上传的空间
String bucket = "bucket_name";
//设置上传的文件的key值
String key = "yourdefinekey";

//普通上传,只需要设置上传的空间名就可以了,第二个参数可以设定token过期时间
PutPolicy put = new PutPolicy(bucket, 3600);

//设置callbackUrl以及callbackBody,七牛将文件名和文件大小回调给业务服务器
put.CallBackUrl = "http://your.domain.com/callback";
put.CallBackBody = "filename=$(fname)&filesize=$(fsize)";

//调用Token()方法生成上传的Token
string upToken = put.Token();
//上传文件的路径
String filePath = "/.../...";

PutRet ret = target.PutFile(upToken, key, filePath, extra);
//打印出相应的信息
Console.WriteLine(ret.Response.ToString());
Console.WriteLine(ret.key);
Console.ReadLine();
}

static void Main(string[] args)
{
//实例化UploadDemo对象并调用设置的upload方法
UploadDemo Upload = new UploadDemo();
Upload.upload();
}

}
}
Loading