Skip to content

Commit 1797a58

Browse files
committed
Fix putExtra
1 parent 283573b commit 1797a58

File tree

10 files changed

+432
-392
lines changed

10 files changed

+432
-392
lines changed

Qiniu.Test/Auth/PutPolicy.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using NUnit.Framework;
33
using Qiniu.RS;
4+
using Qiniu.Util;
45
using Qiniu.Auth.digest;
56

67
namespace Qiniu.Test.FileOp
@@ -21,6 +22,8 @@ public class GetPolicyTest:QiniuTestBase
2122
public void MakeRequestTest()
2223
{
2324
string actual;
25+
FileOpUrl = "http://icattlecoder-private.qiniudn.com/img.jpg?download/avialkjdf" + "橛苛要工苛".ToUrlEncode() ;
26+
2427
actual = GetPolicy.MakeRequest(FileOpUrl);
2528
//System.Diagnostics.Process.Start(actual);
2629
PrintLn(actual);

Qiniu.Test/QiniuTestBase.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ private void Init()
2323
return;
2424

2525
//for make test
26+
Config.ACCESS_KEY = "IT9iP3J9wdXXYsT1p8ns0gWD-CQOdLvIQuyE0FOK";
27+
Config.SECRET_KEY = "zUCzekBtEqTZ4-WJPCGlBrr2PeyYxsYn98LPaivM";
2628

27-
Config.ACCESS_KEY = System.Environment.GetEnvironmentVariable ("QINIU_ACCESS_KEY");
28-
Config.SECRET_KEY = System.Environment.GetEnvironmentVariable ("QINIU_SECRET_KEY");
29-
Bucket =System.Environment.GetEnvironmentVariable ("QINIU_TEST_BUCKET");
30-
DOMAIN =System.Environment.GetEnvironmentVariable ("QINIU_TEST_DOMAIN");
29+
// Config.ACCESS_KEY = System.Environment.GetEnvironmentVariable ("QINIU_ACCESS_KEY");
30+
// Config.SECRET_KEY = System.Environment.GetEnvironmentVariable ("QINIU_SECRET_KEY");
31+
// Bucket =System.Environment.GetEnvironmentVariable ("QINIU_TEST_BUCKET");
32+
// DOMAIN =System.Environment.GetEnvironmentVariable ("QINIU_TEST_DOMAIN");
3133

3234
init = true;
3335
}

Qiniu.Test/RS/RSClientTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public void StatTest()
3838
{
3939
RSClient target = new RSClient();
4040
//YES
41-
EntryPath scope = new EntryPath(Bucket, tmpKeys[0]);
41+
42+
// EntryPath scope = new EntryPath(Bucket, tmpKeys[0]);
43+
EntryPath scope = new EntryPath ("wangming", "bucketMgr.md");
4244
Entry actual;
4345
actual = target.Stat(scope);
4446
Assert.IsTrue(actual.OK, "StatTest Failure");

Qiniu/IO/IOClient.cs

Lines changed: 117 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -5,118 +5,121 @@
55
using Qiniu.Auth;
66
using Qiniu.RPC;
77
using Qiniu.Util;
8-
using System.Collections.Specialized;
9-
10-
namespace Qiniu.IO
11-
{
12-
/// <summary>
13-
/// 上传客户端
14-
/// </summary>
15-
public class IOClient
16-
{
17-
/// <summary>
18-
/// 无论成功或失败,上传结束时触发的事件
19-
/// </summary>
20-
public event EventHandler<PutRet> PutFinished;
21-
22-
private static NameValueCollection getFormData(string upToken, string key, PutExtra extra)
23-
{
24-
NameValueCollection formData = new NameValueCollection();
25-
formData["token"] = upToken;
26-
formData["key"] = key;
27-
if (extra != null && extra.Params != null)
28-
{
29-
if (extra.CheckCrc == CheckCrcType.CHECK_AUTO)
30-
{
31-
formData["crc32"] = extra.Crc32.ToString();
32-
}
33-
foreach (KeyValuePair<string, string> pair in extra.Params)
34-
{
35-
formData[pair.Key] = pair.Value;
36-
}
37-
}
38-
return formData;
39-
}
40-
41-
42-
/// <summary>
43-
/// 上传文件
44-
/// </summary>
45-
/// <param name="upToken"></param>
46-
/// <param name="key"></param>h
47-
/// <param name="localFile"></param>
48-
/// <param name="extra"></param>
49-
public PutRet PutFile(string upToken, string key, string localFile, PutExtra extra)
50-
{
51-
if (!System.IO.File.Exists (localFile)) {
52-
throw new Exception (string.Format ("{0} does not exist", localFile));
53-
}
54-
PutRet ret;
55-
56-
NameValueCollection formData = getFormData(upToken, key, extra);
57-
try
58-
{
59-
CallRet callRet = MultiPart.MultiPost(Config.UP_HOST, formData, localFile);
60-
ret = new PutRet(callRet);
61-
onPutFinished(ret);
62-
return ret;
63-
}
64-
catch (Exception e)
65-
{
66-
ret = new PutRet(new CallRet(HttpStatusCode.BadRequest, e));
67-
onPutFinished(ret);
68-
return ret;
69-
}
70-
}
71-
/// <summary>
72-
/// Puts the file without key.
73-
/// </summary>
74-
/// <returns>The file without key.</returns>
75-
/// <param name="upToken">Up token.</param>
76-
/// <param name="localFile">Local file.</param>
77-
/// <param name="extra">Extra.</param>
78-
public PutRet PutFileWithoutKey(string upToken,string localFile,PutExtra extra)
79-
{
80-
return PutFile (upToken, string.Empty, localFile, extra);
81-
82-
}
83-
84-
/// <summary>
85-
///
86-
/// </summary>
87-
/// <param name="upToken">Up token.</param>
88-
/// <param name="key">Key.</param>
89-
/// <param name="putStream">Put stream.</param>
90-
/// <param name="extra">Extra.</param>
91-
public PutRet Put(string upToken, string key, System.IO.Stream putStream, PutExtra extra)
92-
{
93-
if (!putStream.CanRead) {
94-
throw new Exception ("read put Stream error");
95-
}
96-
PutRet ret;
97-
NameValueCollection formData = getFormData(upToken, key, extra);
98-
try
99-
{
100-
101-
CallRet callRet = MultiPart.MultiPost(Config.UP_HOST, formData, putStream);
102-
ret = new PutRet(callRet);
103-
onPutFinished(ret);
104-
return ret;
105-
}
106-
catch (Exception e)
107-
{
108-
ret = new PutRet(new CallRet(HttpStatusCode.BadRequest, e));
109-
onPutFinished(ret);
110-
return ret;
111-
}
112-
}
113-
114-
protected void onPutFinished(PutRet ret)
115-
{
116-
if (PutFinished != null)
117-
{
118-
PutFinished(this, ret);
119-
}
120-
}
121-
}
8+
using System.Collections.Specialized;
9+
10+
namespace Qiniu.IO
11+
{
12+
/// <summary>
13+
/// 上传客户端
14+
/// </summary>
15+
public class IOClient
16+
{
17+
/// <summary>
18+
/// 无论成功或失败,上传结束时触发的事件
19+
/// </summary>
20+
public event EventHandler<PutRet> PutFinished;
21+
22+
private static NameValueCollection getFormData(string upToken, string key, PutExtra extra)
23+
{
24+
NameValueCollection formData = new NameValueCollection();
25+
formData["token"] = upToken;
26+
formData["key"] = key;
27+
if (extra != null)
28+
{
29+
if (extra.CheckCrc == CheckCrcType.CHECK_AUTO)
30+
{
31+
formData["crc32"] = extra.Crc32.ToString();
32+
}
33+
if (extra.Params != null)
34+
{
35+
foreach (KeyValuePair<string, string> pair in extra.Params)
36+
{
37+
formData[pair.Key] = pair.Value;
38+
}
39+
}
40+
}
41+
return formData;
42+
}
43+
44+
45+
/// <summary>
46+
/// 上传文件
47+
/// </summary>
48+
/// <param name="upToken"></param>
49+
/// <param name="key"></param>h
50+
/// <param name="localFile"></param>
51+
/// <param name="extra"></param>
52+
public PutRet PutFile(string upToken, string key, string localFile, PutExtra extra)
53+
{
54+
if (!System.IO.File.Exists(localFile))
55+
{
56+
throw new Exception(string.Format("{0} does not exist", localFile));
57+
}
58+
PutRet ret;
59+
60+
NameValueCollection formData = getFormData(upToken, key, extra);
61+
try
62+
{
63+
CallRet callRet = MultiPart.MultiPost(Config.UP_HOST, formData, localFile);
64+
ret = new PutRet(callRet);
65+
onPutFinished(ret);
66+
return ret;
67+
}
68+
catch (Exception e)
69+
{
70+
ret = new PutRet(new CallRet(HttpStatusCode.BadRequest, e));
71+
onPutFinished(ret);
72+
return ret;
73+
}
74+
}
75+
/// <summary>
76+
/// Puts the file without key.
77+
/// </summary>
78+
/// <returns>The file without key.</returns>
79+
/// <param name="upToken">Up token.</param>
80+
/// <param name="localFile">Local file.</param>
81+
/// <param name="extra">Extra.</param>
82+
public PutRet PutFileWithoutKey(string upToken, string localFile, PutExtra extra)
83+
{
84+
return PutFile(upToken, string.Empty, localFile, extra);
85+
}
86+
87+
/// <summary>
88+
///
89+
/// </summary>
90+
/// <param name="upToken">Up token.</param>
91+
/// <param name="key">Key.</param>
92+
/// <param name="putStream">Put stream.</param>
93+
/// <param name="extra">Extra.</param>
94+
public PutRet Put(string upToken, string key, System.IO.Stream putStream, PutExtra extra)
95+
{
96+
if (!putStream.CanRead)
97+
{
98+
throw new Exception("read put Stream error");
99+
}
100+
PutRet ret;
101+
NameValueCollection formData = getFormData(upToken, key, extra);
102+
try
103+
{
104+
CallRet callRet = MultiPart.MultiPost(Config.UP_HOST, formData, putStream);
105+
ret = new PutRet(callRet);
106+
onPutFinished(ret);
107+
return ret;
108+
}
109+
catch (Exception e)
110+
{
111+
ret = new PutRet(new CallRet(HttpStatusCode.BadRequest, e));
112+
onPutFinished(ret);
113+
return ret;
114+
}
115+
}
116+
117+
protected void onPutFinished(PutRet ret)
118+
{
119+
if (PutFinished != null)
120+
{
121+
PutFinished(this, ret);
122+
}
123+
}
124+
}
122125
}

Qiniu/IO/PutExtra.cs

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,54 @@
1-
using System;
2-
using System.Collections.Generic;
3-
4-
namespace Qiniu.IO
5-
{
6-
public enum CheckCrcType
7-
{
8-
/// <summary>
9-
/// default
10-
/// </summary>
11-
DEFAULT_CHECK = -1,
12-
/// <summary>
13-
/// 表示不进行 crc32 校验
14-
/// </summary>
15-
NO_CHECK = 0,
16-
/// <summary>
17-
///对于 Put 等同于 CheckCrc = 2;对于 PutFile 会自动计算 crc32 值
18-
/// </summary>
19-
CHECK_AUTO = 1,
20-
/// <summary>
21-
/// 表示进行 crc32 校验,且 crc32 值就是PutExtra:Crc32
22-
/// </summary>
23-
CHECK = 2
24-
}
25-
26-
public class PutExtra
27-
{
28-
public Dictionary<string, string> Params{ get; set; }
29-
30-
public string MimeType { get; set; }
31-
32-
public Int32 Crc32 { get; set; }
33-
34-
public CheckCrcType CheckCrc { get; set; }
35-
36-
public string Scope { get; set; }
37-
38-
public PutExtra ()
39-
{
40-
Crc32 = -1;
41-
}
42-
43-
public PutExtra (string bucket, string mimeType)
44-
{
45-
Scope = bucket;
46-
MimeType = mimeType;
47-
Crc32 = -1;
48-
}
49-
}
50-
}
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Qiniu.IO
5+
{
6+
public enum CheckCrcType
7+
{
8+
/// <summary>
9+
/// default
10+
/// </summary>
11+
DEFAULT_CHECK = -1,
12+
/// <summary>
13+
/// 表示不进行 crc32 校验
14+
/// </summary>
15+
NO_CHECK = 0,
16+
/// <summary>
17+
///对于 Put 等同于 CheckCrc = 2;对于 PutFile 会自动计算 crc32 值
18+
/// </summary>
19+
CHECK_AUTO = 1,
20+
/// <summary>
21+
/// 表示进行 crc32 校验,且 crc32 值就是PutExtra:Crc32
22+
/// </summary>
23+
CHECK = 2
24+
}
25+
/// <summary>
26+
///
27+
/// </summary>
28+
public class PutExtra
29+
{
30+
/// <summary>
31+
///
32+
/// </summary>
33+
public Dictionary<string, string> Params { get; set; }
34+
/// <summary>
35+
///
36+
/// </summary>
37+
public Int32 Crc32 { get; set; }
38+
/// <summary>
39+
///
40+
/// </summary>
41+
public CheckCrcType CheckCrc { get; set; }
42+
43+
public string MimeType { get; set; }
44+
45+
/// <summary>
46+
///
47+
/// </summary>
48+
public PutExtra()
49+
{
50+
Crc32 = -1;
51+
}
52+
53+
}
54+
}

Qiniu/IO/PutRet.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
43
using Qiniu.RPC;
54
using Newtonsoft.Json;
65

0 commit comments

Comments
 (0)