Skip to content

Commit

Permalink
Merge pull request #122 from fengyhack/master
Browse files Browse the repository at this point in the history
版本更新v7.2.4 部分细节优化与错误修正
  • Loading branch information
fengyhack committed Jan 12, 2017
2 parents 73078b6 + 0e59bba commit a1553e0
Show file tree
Hide file tree
Showing 13 changed files with 571 additions and 234 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
**2017-01-12**

最新版本v7.2.4,适用于.NET Framework 2.0+ 和.NET Core

新增:分片上传(ResumableUploader)的uploadFile拥有更多的重载版本。

新增:上传文件支持用户自定义参数(extraParams)

* * *

**2017-01-10**

最新版本v7.2.3,适用于.NET Framework 2.0+ 和.NET Core
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

以下文档用于检索SDK接口、属性说明,它将有助于您理解SDK的结构。

* [HTML在线浏览](http://oiy037d6a.bkt.clouddn.com/csharp-sdk-ref-v7.2.3/index.html)
* [HTML在线浏览](http://oiy037d6a.bkt.clouddn.com/csharp-sdk-ref-v7.2.4/index.html)

* [CHM文件下载](http://oiy037d6a.bkt.clouddn.com/QiniuCSharpSDK-Ref-v7.2.3.chm)
* [CHM文件下载](http://oiy037d6a.bkt.clouddn.com/QiniuCSharpSDK-Ref-v7.2.4.chm)

以下文档/链接提供一些基本示例,参考这些示例可以帮助您更快熟悉如何使用这套SDK。

* [github | csharp-sdk-examples](https://github.com/fengyhack/csharp-sdk-examples)

* [C# SDK使用指南 | 代码示例](http://oiy037d6a.bkt.clouddn.com/csharp-sdk-man-v7.2.3/index.html)
* [C# SDK使用指南 | 代码示例](http://oiy037d6a.bkt.clouddn.com/csharp-sdk-man-v7.2.4/index.html)

##如何安装

Expand Down
6 changes: 3 additions & 3 deletions doc/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ <h2 id="sdk文档">SDK文档</h2>

<p>以下文档用于检索SDK接口、属性说明,它将有助于您理解SDK的结构。</p>

<ul><li><p><a href="http://oiy037d6a.bkt.clouddn.com/csharp-sdk-ref-v7.2.2/index.html" target="_blank">HTML在线浏览</a></p></li>
<li><p><a href="http://oiy037d6a.bkt.clouddn.com/QiniuCSharpSDK-Ref-v7.2.2.chm" target="_blank">CHM文件下载</a></p></li>
<ul><li><p><a href="http://oiy037d6a.bkt.clouddn.com/csharp-sdk-ref-v7.2.4/index.html" target="_blank">HTML在线浏览</a></p></li>
<li><p><a href="http://oiy037d6a.bkt.clouddn.com/QiniuCSharpSDK-Ref-v7.2.4.chm" target="_blank">CHM文件下载</a></p></li>
</ul>

<p>以下文档/链接提供一些基本示例,参考这些示例可以帮助您更快熟悉如何使用这套SDK。</p>

<ul><li><p><a href="https://github.com/fengyhack/csharp-sdk-shared-examples" target="_blank">github | csharp-sdk-examples</a></p></li>
<li><p><a href="http://oiy037d6a.bkt.clouddn.com/csharp-sdk-man-v7.2.2/index.html" target="_blank">C# SDK使用指南 | 代码示例</a></p></li>
<li><p><a href="http://oiy037d6a.bkt.clouddn.com/csharp-sdk-man-v7.2.4/index.html" target="_blank">C# SDK使用指南 | 代码示例</a></p></li>
</ul>


Expand Down
Binary file modified doc/README.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Qiniu/Common/QiniuCSharpSDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class QiniuCSharpSDK
/// <summary>
/// SDK版本号
/// </summary>
public const string VERSION = "7.2.2.0";
public const string VERSION = "7.2.4";

/// <summary>
/// SDK模块
Expand Down
119 changes: 16 additions & 103 deletions src/Qiniu/Http/HttpManager.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Qiniu/IO/DownloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public HttpResult downloadPriv(string signedUrl,string saveasFile)

try
{
result = httpManager.get(signedUrl, null, null, true);
result = httpManager.get(signedUrl, null, true);
if (result.Code == HttpHelper.STATUS_CODE_OK)
{
using (FileStream fs = File.Create(saveasFile, result.Data.Length))
Expand Down Expand Up @@ -121,7 +121,7 @@ public static HttpResult download(string url,string saveasFile)
{
HttpManager httpManager = new HttpManager();

result = httpManager.get(url, null, null, true);
result = httpManager.get(url, null, true);
if (result.Code == HttpHelper.STATUS_CODE_OK)
{
using (FileStream fs = File.Create(saveasFile, result.Data.Length))
Expand Down
474 changes: 383 additions & 91 deletions src/Qiniu/IO/ResumableUploader.cs

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions src/Qiniu/IO/SimpleUploader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using Qiniu.Common;
using Qiniu.Http;

Expand Down Expand Up @@ -98,6 +99,76 @@ public HttpResult uploadFile(string localFile, string saveKey, string token)
return result;
}

/// <summary>
/// 上传文件 - 可附加自定义参数
/// </summary>
/// <param name="localFile">待上传的本地文件</param>
/// <param name="saveKey">要保存的目标文件名称</param>
/// <param name="token">上传凭证</param>
/// <param name="extraParams">用户自定义的附加参数</param>
/// <returns></returns>
public HttpResult uploadFile(string localFile, string saveKey, string token, Dictionary<string,string> extraParams)
{
HttpResult result = new HttpResult();

try
{
string boundary = HttpHelper.createFormDataBoundary();
string sep = "--" + boundary;
StringBuilder sb = new StringBuilder();

sb.AppendLine(sep);

sb.AppendLine("Content-Disposition: form-data; name=key\r\n");
sb.AppendLine(saveKey);
sb.AppendLine(sep);

sb.AppendLine("Content-Disposition: form-data; name=token\r\n");
sb.AppendLine(token);
sb.AppendLine(sep);

foreach (var d in extraParams)
{
sb.AppendFormat("Content-Disposition: form-data; name=\"{0}\"\r\n\r\n", d.Key);
sb.AppendLine(d.Value);
sb.AppendLine(sep);
}

string filename = Path.GetFileName(localFile);
sb.AppendFormat("Content-Disposition: form-data; name=file; filename={0}\r\n\r\n", filename);

byte[] partData1 = Encoding.UTF8.GetBytes(sb.ToString());
byte[] partData2 = File.ReadAllBytes(localFile);
byte[] partData3 = Encoding.UTF8.GetBytes(string.Format("\r\n{0}--\r\n", sep));

MemoryStream ms = new MemoryStream();
ms.Write(partData1, 0, partData1.Length);
ms.Write(partData2, 0, partData2.Length);
ms.Write(partData3, 0, partData3.Length);

result = httpManager.postMultipart(uploadHost, ms.ToArray(), boundary, null);
result.RefText += string.Format("[SimpleUpload] Uploaded: \"{0}\" ==> \"{1}\", @{2}\n",
localFile, saveKey, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff"));
}
catch (Exception ex)
{
StringBuilder sb = new StringBuilder("[SimpleUpload] Error: ");
Exception e = ex;
while (e != null)
{
sb.Append(e.Message + " ");
e = e.InnerException;
}

sb.AppendFormat(" @{0}\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff"));

result.RefCode = HttpHelper.STATUS_CODE_EXCEPTION;
result.RefText += sb.ToString();
}

return result;
}

/// <summary>
/// 上传数据流
/// </summary>
Expand Down
55 changes: 53 additions & 2 deletions src/Qiniu/IO/UploadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ public class UploadManager
// 是否从CDN上传
private bool UPLOAD_FROM_CDN = false;

// 上传进度处理器 - 仅用于上传大文件
private UploadProgressHandler upph = null;

// 上传控制器 - 仅用于上传大文件
private UploadController upctl = null;

// 上传记录文件 - 仅用于上传大文件
private string recordFile = null;

/// <summary>
/// 初始化
/// </summary>
Expand All @@ -36,6 +45,33 @@ public UploadManager(long putThreshold = 1048576, bool uploadFromCDN = false)
UPLOAD_FROM_CDN = uploadFromCDN;
}

/// <summary>
/// 设置上传进度处理器-仅对于上传大文件有效
/// </summary>
/// <param name="upph">上传进度处理器</param>
public void setUploadProgressHandler(UploadProgressHandler upph)
{
this.upph = upph;
}

/// <summary>
/// 设置上传控制器-仅对于上传大文件有效
/// </summary>
/// <param name="upctl">上传控制器</param>
public void setUploadController(UploadController upctl)
{
this.upctl = upctl;
}

/// <summary>
/// 设置断点记录文件-仅对于上传大文件有效
/// </summary>
/// <param name="recordFile">记录文件</param>
public void setRecordFile(string recordFile)
{
this.recordFile = recordFile;
}

/// <summary>
/// 设置分片上传的“片”大小(单位:字节)
/// </summary>
Expand Down Expand Up @@ -73,8 +109,23 @@ public HttpResult uploadFile(string localFile, string saveKey, string token)
FileInfo fi = new FileInfo(localFile);
if (fi.Length > PUT_THRESHOLD)
{
ResumableUploader ru = new ResumableUploader(UPLOAD_FROM_CDN);
result = ru.uploadFile(localFile, saveKey, token);
if (string.IsNullOrEmpty(recordFile))
{
recordFile = "QiniuRU_" + Util.StringHelper.calcMD5(localFile + saveKey);
}

if (upph == null)
{
upph = new UploadProgressHandler(ResumableUploader.defaultUploadProgressHandler);
}

if (upctl == null)
{
upctl = new UploadController(ResumableUploader.defaultUploadController);
}

ResumableUploader ru = new ResumableUploader(UPLOAD_FROM_CDN, CHUNK_UNIT);
result = ru.uploadFile(localFile, saveKey, token, recordFile, upph, upctl);
}
else
{
Expand Down
46 changes: 23 additions & 23 deletions src/Qiniu/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,45 @@

#if Net20

[assembly: AssemblyProduct("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 2.0)")]
[assembly: AssemblyTitle("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 2.0)")]
[assembly: AssemblyDescription("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 2.0)")]
[assembly: AssemblyProduct("Qiniu (Cloud) C# SDK v7.2.4 (.NET 2.0)")]
[assembly: AssemblyTitle("Qiniu (Cloud) C# SDK v7.2.4 (.NET 2.0)")]
[assembly: AssemblyDescription("Qiniu (Cloud) C# SDK v7.2.4 (.NET 2.0)")]

#elif Net35

[assembly: AssemblyProduct("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 3.5)")]
[assembly: AssemblyTitle("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 3.5)")]
[assembly: AssemblyDescription("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 3.5)")]
[assembly: AssemblyProduct("Qiniu (Cloud) C# SDK v7.2.4 (.NET 3.5)")]
[assembly: AssemblyTitle("Qiniu (Cloud) C# SDK v7.2.4 (.NET 3.5)")]
[assembly: AssemblyDescription("Qiniu (Cloud) C# SDK v7.2.4 (.NET 3.5)")]

#elif Net40

[assembly: AssemblyProduct("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 4.0)")]
[assembly: AssemblyTitle("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 4.0)")]
[assembly: AssemblyDescription("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 4.0)")]
[assembly: AssemblyProduct("Qiniu (Cloud) C# SDK v7.2.4 (.NET 4.0)")]
[assembly: AssemblyTitle("Qiniu (Cloud) C# SDK v7.2.4 (.NET 4.0)")]
[assembly: AssemblyDescription("Qiniu (Cloud) C# SDK v7.2.4 (.NET 4.0)")]

#elif Net45

[assembly: AssemblyProduct("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 4.5)")]
[assembly: AssemblyTitle("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 4.5)")]
[assembly: AssemblyDescription("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 4.5)")]
[assembly: AssemblyProduct("Qiniu (Cloud) C# SDK v7.2.4 (.NET 4.5)")]
[assembly: AssemblyTitle("Qiniu (Cloud) C# SDK v7.2.4 (.NET 4.5)")]
[assembly: AssemblyDescription("Qiniu (Cloud) C# SDK v7.2.4 (.NET 4.5)")]

#elif Net46

[assembly: AssemblyProduct("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 4.6)")]
[assembly: AssemblyTitle("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 4.6)")]
[assembly: AssemblyDescription("Qiniu (Cloud) C# SDK v7.2.3.0 (.NET 4.6)")]
[assembly: AssemblyProduct("Qiniu (Cloud) C# SDK v7.2.4 (.NET 4.6)")]
[assembly: AssemblyTitle("Qiniu (Cloud) C# SDK v7.2.4 (.NET 4.6)")]
[assembly: AssemblyDescription("Qiniu (Cloud) C# SDK v7.2.4 (.NET 4.6)")]

#elif NetStandard16

[assembly: AssemblyProduct("Qiniu (Cloud) C# SDK v7.2.3.0 (.NETStandard 1.6.0)")]
[assembly: AssemblyTitle("Qiniu (Cloud) C# SDK v7.2.3.0 (.NETStandard 1.6.0)")]
[assembly: AssemblyDescription("Qiniu (Cloud) C# SDK v7.2.3.0 (.NETStandard 1.6.0)")]
[assembly: AssemblyProduct("Qiniu (Cloud) C# SDK v7.2.4 (.NETStd 1.6)")]
[assembly: AssemblyTitle("Qiniu (Cloud) C# SDK v7.2.4 (.NETStd 1.6)")]
[assembly: AssemblyDescription("Qiniu (Cloud) C# SDK v7.2.4 (.NETStd 1.6)")]

#else

[assembly: AssemblyProduct("Qiniu (Cloud) C# SDK v7.2.3.0")]
[assembly: AssemblyTitle("Qiniu (Cloud) C# SDK v7.2.3.0")]
[assembly: AssemblyDescription("Qiniu (Cloud) C# SDK v7.2.3.0")]
[assembly: AssemblyProduct("Qiniu (Cloud) C# SDK v7.2.4")]
[assembly: AssemblyTitle("Qiniu (Cloud) C# SDK v7.2.4")]
[assembly: AssemblyDescription("Qiniu (Cloud) C# SDK v7.2.4")]

#endif

Expand All @@ -63,6 +63,6 @@
[assembly: Guid("957cd434-8b12-46ce-980b-09ca26ed340d")]

[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyVersion("7.2.3.0")]
[assembly: AssemblyFileVersion("7.2.3.0")]
[assembly: AssemblyVersion("7.2.4")]
[assembly: AssemblyFileVersion("7.2.4")]

6 changes: 3 additions & 3 deletions src/Qiniu/RSF/OperationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public HttpResult dfopText(string fop, string text)
sb.AppendFormat("{0}--\r\n", sep);
byte[] data = Encoding.UTF8.GetBytes(sb.ToString());

result = httpManager.postMultipart(dfopUrl, data, boundary, token, null, true);
result = httpManager.postMultipart(dfopUrl, data, boundary, token, true);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -246,7 +246,7 @@ public HttpResult dfopUrl(string fop, string url)
string dfopUrl = string.Format("{0}/dfop?fop={1}&url={2}", Config.DFOP_API_HOST, fop, encodedUrl);
string token = createManageToken(dfopUrl, null);

result = httpManager.post(dfopUrl, token, null, true);
result = httpManager.post(dfopUrl, token, true);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -299,7 +299,7 @@ public HttpResult dfopData(string fop, string localFile)
ms.Write(partData2, 0, partData2.Length);
ms.Write(partData3, 0, partData3.Length);

result = httpManager.postMultipart(dfopUrl, ms.ToArray(), boundary, token, null, true);
result = httpManager.postMultipart(dfopUrl, ms.ToArray(), boundary, token, true);
}
catch (Exception ex)
{
Expand Down
6 changes: 3 additions & 3 deletions src/project.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"title": "Qiniu (Cloud) C# SDK v7.2.3.0 (.NETStandard 1.6.0)",
"title": "Qiniu (Cloud) C# SDK v7.2.4 (.NETStd 1.6)",
"copyright": "Copyright © 2017",
"description": "Qiniu (Cloud) C# SDK v7.2.3.0 (.NETStandard 1.6.0)",
"version": "7.2.3-0",
"description": "Qiniu (Cloud) C# SDK v7.2.4 (.NETStd 1.6)",
"version": "7.2.4-0",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
Expand Down

0 comments on commit a1553e0

Please sign in to comment.