Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a35437

Browse files
committed
fix
1 parent e4e186f commit 0a35437

File tree

6 files changed

+64
-35
lines changed

6 files changed

+64
-35
lines changed

demo/Program.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,32 @@ class MainClass
1111
public static void Main (string[] args)
1212
{
1313
// 初始化qiniu配置,主要是API Keys
14-
qiniu.Config.ACCESS_KEY = "IT9iP3J9wdXXYsT1p8ns0gWD-CQOdLvIQuyE0FOK";
14+
qiniu.Config.ACCESS_KEY = "IT9iP3J9wdXXYsT1p8ns0gWD-CQOdLvIQuyE0FOi";
1515
qiniu.Config.SECRET_KEY = "zUCzekBtEqTZ4-WJPCGlBrr2PeyYxsYn98LPaivM";
1616

1717
/**********************************************************************
1818
可以用下面的方法从配置文件中初始化
1919
qiniu.Config.InitFromAppConfig ();
2020
**********************************************************************/
2121

22-
23-
string localfile = "/Users/icattlecoder/Movies/tzd.rmvb";
24-
string bucket = "icattlecoder";
25-
string qiniukey = "tzd.rmvb";
22+
string localfile = "/Users/icattlecoder/Movies/tzd.rmvb";
23+
string bucket = "icattlecoder";
24+
string qiniukey = "tzd.rmvb";
25+
2626
//======================================================================
2727
{
2828
QiniuFile qfile = new QiniuFile (bucket, qiniukey, localfile);
29-
ResumbalePutEx puttedCtx = new ResumbalePutEx (localfile);
29+
ResumbleUploadEx puttedCtx = new ResumbleUploadEx (localfile);
3030
ManualResetEvent done = new ManualResetEvent (false);
3131
qfile.UploadCompleted += (sender, e) => {
32-
Console.WriteLine (e.RawString);
32+
Console.WriteLine (e.key);
33+
Console.WriteLine (e.Hash);
3334
done.Set ();
3435
};
3536
qfile.UploadFailed += (sender, e) => {
3637
Console.WriteLine (e.Error.ToString ());
37-
done.Set ();
3838
puttedCtx.Save();
39+
done.Set ();
3940
};
4041
qfile.UploadProgressChanged += (sender, e) => {
4142
int percentage = (int)(100 * e.BytesSent / e.TotalBytes);
@@ -45,7 +46,12 @@ public static void Main (string[] args)
4546
puttedCtx.Add(e.Index,e.Ctx);
4647
puttedCtx.Save();
4748
};
48-
// 上传为异步操作
49+
qfile.UploadBlockFailed += (sender, e) => {
50+
//
51+
52+
};
53+
54+
//上传为异步操作
4955
//上传本地文件到七牛云存储
5056
qfile.Upload (puttedCtx.PuttedCtx);
5157
done.WaitOne ();
@@ -58,8 +64,9 @@ public static void Main (string[] args)
5864
QiniuFile qfile = new QiniuFile (bucket, qiniukey);
5965
QiniuFileInfo finfo = qfile.Stat ();
6066
if (finfo != null) {
67+
qfile.Move("cloudcomment","movetest");
6168
//删除七牛云空间的文件
62-
qfile.Delete ();
69+
//qfile.Delete ();
6370
}
6471
} catch (QiniuWebException e) {
6572
Console.WriteLine (e.Error.HttpCode);

demo/demo.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
<ItemGroup>
3535
<Compile Include="Program.cs" />
3636
<Compile Include="Properties\AssemblyInfo.cs" />
37-
<Compile Include="QiniuResumbleHelper.cs" />
3837
</ItemGroup>
3938
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
4039
<ItemGroup>

sdk/QiniuConf.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,8 @@ public class Config
4444
/// </summary>
4545
public static void InitFromAppConfig()
4646
{
47-
USER_AGENT = System.Configuration.ConfigurationManager.AppSettings["USER_AGENT"];
4847
ACCESS_KEY = System.Configuration.ConfigurationManager.AppSettings["ACCESS_KEY"];
4948
SECRET_KEY = System.Configuration.ConfigurationManager.AppSettings["SECRET_KEY"];
50-
RS_HOST = System.Configuration.ConfigurationManager.AppSettings["RS_HOST"];
51-
UP_HOST = System.Configuration.ConfigurationManager.AppSettings["UP_HOST"];
52-
RSF_HOST = System.Configuration.ConfigurationManager.AppSettings["RSF_HOST"];
53-
PREFETCH_HOST = System.Configuration.ConfigurationManager.AppSettings["PREFETCH_HOST"];
5449
}
5550
}
5651
}

sdk/QiniuFile.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,34 @@ public bool Delete(MAC mac=null){
155155
} catch (Exception e) {
156156
throw e;
157157
}
158-
}
158+
}
159+
160+
/// <summary>
161+
/// Move the specified destBucket, destKey and mac.
162+
/// </summary>
163+
/// <param name="destBucket">Destination bucket.</param>
164+
/// <param name="destKey">Destination key.</param>
165+
/// <param name="mac">Mac.</param>
166+
public bool Move(string destBucket,string destKey,MAC mac=null){
167+
if (mac == null) {
168+
mac = new MAC ();
169+
}
170+
string url = string.Format ("{0}/{1}/{2}/{3}",
171+
Config.RS_HOST,
172+
"move",
173+
Base64URLSafe.Encode (this.bucketName+":"+this.key),
174+
Base64URLSafe.Encode (destBucket+":"+destKey));
175+
try {
176+
using (QiniuWebClient client = new QiniuWebClient ()) {
177+
client.Call (url, mac);
178+
return true;
179+
}
180+
} catch (WebException e) {
181+
throw new QiniuWebException(e);
182+
} catch (Exception e) {
183+
throw e;
184+
}
185+
}
159186

160187
/// <summary>
161188
/// Asyncs the upload.
@@ -242,6 +269,7 @@ private void uploadBigFile(string token,BlkputRet[] puttedBlk=null){
242269
for (int i = 0; i < blockcount; i++) {
243270
if (puttedBlk!=null&&i< puttedBlk.Length) {
244271
blkRets[i] = puttedBlk[i];
272+
totalSent +=(long)blkRets[i].offset;
245273
continue;
246274
}
247275
if (i == blockcount - 1) {
@@ -346,8 +374,6 @@ private static string getDefalutToken(string bucketName,string key){
346374
return policy.Token ();
347375
}
348376
#endregion
349-
350-
351377
}
352378

353379
[JsonObject(MemberSerialization.OptIn)]

demo/QiniuResumbleHelper.cs renamed to sdk/QiniuResumbleUploadEx.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
using System;
2+
using System.IO;
23
using System.Text;
3-
using System.Collections.Generic;
44
using System.Security.Cryptography;
5-
using System.IO;
6-
using System.IO.Compression;
7-
using qiniu;
8-
namespace demo
5+
using System.Collections.Generic;
6+
7+
namespace qiniu
98
{
10-
public class ResumbalePutEx
9+
/// <summary>
10+
/// 断点续传.
11+
/// </summary>
12+
public class ResumbleUploadEx
1113
{
1214
private string puttedCtxDir;
1315
private string fileName;
1416
private string puttedCtxFileName;
1517
private Dictionary<int,BlkputRet> puttedCtx;
1618

1719
/// <summary>
18-
/// Gets the putted context.
20+
/// 获取已上传的结果.
1921
/// </summary>
2022
/// <value>The putted context.</value>
2123
public BlkputRet[] PuttedCtx {
@@ -27,7 +29,7 @@ public BlkputRet[] PuttedCtx {
2729
if (this.puttedCtx.ContainsKey (i)) {
2830
result [i] = this.puttedCtx [i];
2931
} else {
30-
this.Delete ();
32+
this.Clear ();
3133
return null;
3234
}
3335
}
@@ -39,8 +41,8 @@ public BlkputRet[] PuttedCtx {
3941
/// Initializes a new instance of the <see cref="demo.ResumbalePutEx"/> class.
4042
/// </summary>
4143
/// <param name="filename">Filename.</param>
42-
/// <param name="puttedCtxDir">Putted context dir.default set to System TempPath</param>
43-
public ResumbalePutEx (string filename, string puttedCtxDir=null){
44+
/// <param name="puttedCtxDir">断点续传上传结果持久化存放目录. 默认存放在系统临时文件夹。</param>
45+
public ResumbleUploadEx (string filename, string puttedCtxDir=null){
4446
if (!File.Exists (filename)) {
4547
throw new Exception(string.Format("{0} does not exist", filename));
4648
}
@@ -79,7 +81,7 @@ private Dictionary<int,BlkputRet> initloadPuttedCtx(){
7981
}
8082

8183
/// <summary>
82-
/// Save this putted result to disk file.
84+
/// 保存持久化结果至磁盘文件
8385
/// </summary>
8486
public void Save(){
8587
StringBuilder sb = new StringBuilder ();
@@ -91,7 +93,7 @@ public void Save(){
9193
}
9294

9395
/// <summary>
94-
///
96+
/// 保存持久化结果至内存
9597
/// </summary>
9698
/// <param name="tempFileName"></param>
9799
/// <param name="idx"></param>
@@ -102,7 +104,7 @@ public void Add(int idx, BlkputRet ret)
102104
}
103105

104106
/// <summary>
105-
/// Adds the and sync.
107+
/// 保存持久化结果至内存和文件.
106108
/// </summary>
107109
/// <param name="idx">Index.</param>
108110
/// <param name="ret">Ret.</param>
@@ -112,9 +114,9 @@ public void AddAndSave(int idx,BlkputRet ret){
112114
}
113115

114116
/// <summary>
115-
/// Delete this instance.
117+
/// 清除上传持久化结果
116118
/// </summary>
117-
public void Delete(){
119+
public void Clear(){
118120
if (File.Exists (this.puttedCtxFileName)) {
119121
this.puttedCtx.Clear ();
120122
File.Delete (this.puttedCtxFileName);
@@ -138,4 +140,3 @@ private static string getFileBase64Sha1(string filename)
138140
}
139141
}
140142

141-

sdk/qiniu.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<Compile Include="QiniuEventArgs.cs" />
4848
<Compile Include="QiniuPutPolicy.cs" />
4949
<Compile Include="QiniuMAC.cs" />
50+
<Compile Include="QiniuResumbleUploadEx.cs" />
5051
</ItemGroup>
5152
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
5253
</Project>

0 commit comments

Comments
 (0)