Skip to content

Commit c773572

Browse files
committed
fix
1 parent a4dc95b commit c773572

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,73 @@ UploadBlockFailed; | 上传块失败
6262
## 文件操作
6363
简单的实现了文件的基本信息获取及删除操作,分别为`Stat``Delete`
6464

65+
# 完整示例
66+
67+
```
68+
using System;
69+
using qiniu;
70+
using System.Threading;
71+
72+
namespace demo
73+
{
74+
class MainClass
75+
{
76+
public static void Main (string[] args)
77+
{
78+
// 初始化qiniu配置,主要是API Keys
79+
qiniu.Config.ACCESS_KEY = "IT9iP3J9wdXXYsT1p8ns0gWD-CQOdLvIQuyE0FOi";
80+
qiniu.Config.SECRET_KEY = "zUCzekBtEqTZ4-WJPCGlBrr2PeyYxsYn98LxaivM";
81+
82+
/**********************************************************************
83+
可以用下面的方法从配置文件中初始化
84+
qiniu.Config.InitFromAppConfig ();
85+
**********************************************************************/
86+
87+
//==========================上传文件=========================================
88+
{
89+
QiniuFile qfile = new QiniuFile ("<input your bucket name>", "<input qiniu file key>", "<local disk file path");
90+
ManualResetEvent done = new ManualResetEvent (false);
91+
//上传完成事件
92+
qfile.UploadCompleted += (sender, e) => {
93+
Console.WriteLine (e.RawString);
94+
done.Set ();
95+
};
96+
//上传失败事件
97+
qfile.UploadFailed += (sender, e) => {
98+
Console.WriteLine (e.Error.ToString ());
99+
done.Set ();
100+
};
101+
//上传进度事件,可用于百分比进度显示,网速计算
102+
qfile.UploadProgressChanged += (sender, e) => {
103+
int percentage = (int)(100 * e.BytesSent / e.TotalBytes);
104+
Console.Write (percentage);
105+
};
106+
// 上传为异步操作
107+
// 上传本地文件到七牛云存储
108+
qfile.Upload ();
109+
done.WaitOne ();
110+
}
111+
112+
//======================================================================
113+
{
114+
115+
try {
116+
QiniuFile qfile = new QiniuFile ("<input your bucket Name>", "<input qiniu file key>");
117+
QiniuFileInfo finfo = qfile.Stat ();
118+
if (finfo != null) {
119+
//删除七牛云空间的文件
120+
qfile.Delete ();
121+
}
122+
} catch (QiniuWebException e) {
123+
Console.WriteLine (e.Error.HttpCode);
124+
Console.WriteLine (e.Error.ToString ());
125+
}
126+
}
127+
}
128+
}
129+
}
130+
```
131+
65132
<a id="issue"></a>
66133
# 问题反馈
67134
[https://github.com/icattlecoder/qiniu-csharp-sdk/issues/new](https://github.com/icattlecoder/qiniu-csharp-sdk/issues/new)

0 commit comments

Comments
 (0)