Skip to content

Commit fb7c589

Browse files
committed
更新-增加UpCompleteHandler示例代码
1 parent 2667fe7 commit fb7c589

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

examples/ResumableUpload.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,39 @@ public static void uploadBigFile()
2525
string token = Auth.createUploadToken(putPolicy, mac);
2626

2727
ResumeRecorder rr = new ResumeRecorder(recordPath);
28-
ResumeUploader ru = new ResumeUploader(rr, recordFile, localFile, saveKey, token, null, null);
29-
28+
29+
UploadOptions uploadOptions = new UploadOptions(
30+
null, // ExtraParams
31+
null, // MimeType
32+
false, // CheckCrc32
33+
new UpProgressHandler(OnUploadProgressChanged), // 上传进度
34+
null // CancelSignal
35+
);
36+
37+
UpCompletionHandler uploadCompleted = new UpCompletionHandler(OnUploadCompleted); // 上传完毕
38+
39+
ResumeUploader ru = new ResumeUploader(
40+
rr, // 续传记录
41+
recordFile, // 续传记录文件
42+
localFile, // 待上传的本地文件
43+
saveKey, // 要保存的文件名
44+
token, // 上传凭证
45+
uploadOptions, // 上传选项(其中包含进度处理),可为null
46+
uploadCompleted // 上传完毕事件处理
47+
);
48+
3049
ru.uploadFile();
3150
}
51+
52+
private static void OnUploadProgressChanged(string key,double percent)
53+
{
54+
// percent = [0(开始)~1.0(完成)]
55+
}
56+
57+
private static void OnUploadCompleted(string key,ResponseInfo respInfo,string respJson)
58+
{
59+
// respInfo.StatusCode
60+
// respJson是返回的json消息,示例: { "key":"FILE","hash":"HASH","fsize":FILE_SIZE }
61+
}
3262
}
3363
}

examples/SimpleUpload.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Qiniu.Util;
22
using Qiniu.Storage;
3+
using Qiniu.Http;
34

45
namespace QiniuDemo
56
{
@@ -19,13 +20,26 @@ public static void uploadFile()
1920
putPolicy.DeleteAfterDays = 1;
2021
string token = Auth.createUploadToken(putPolicy, mac);
2122

23+
UploadOptions uploadOptions = null;
24+
25+
// 上传完毕事件处理
26+
UpCompletionHandler uploadCompleted = new UpCompletionHandler(OnUploadCompleted);
27+
2228
// 方式1:使用UploadManager
29+
//默认设置 Qiniu.Common.Config.PUT_THRESHOLD = 512*1024;
30+
//可以适当修改,UploadManager会根据这个阈值自动选择是否使用分片(Resumable)上传
2331
UploadManager um = new UploadManager();
24-
um.uploadFile(localFile, saveKey, token, null, null);
32+
um.uploadFile(localFile, saveKey, token, uploadOptions, uploadCompleted);
2533

2634
// 方式2:使用FormManager
2735
//FormUploader fm = new FormUploader();
28-
//fm.uploadFile(localFile, saveKey, token, null, null);
36+
//fm.uploadFile(localFile, saveKey, token, uploadOptions, uploadCompleted);
37+
}
38+
39+
private static void OnUploadCompleted(string key, ResponseInfo respInfo, string respJson)
40+
{
41+
// respInfo.StatusCode
42+
// respJson是返回的json消息,示例: { "key":"FILE","hash":"HASH","fsize":FILE_SIZE }
2943
}
3044
}
3145
}

0 commit comments

Comments
 (0)