Skip to content

Commit 7835573

Browse files
committed
Merge pull request #62 from zheniantoushipashi/add-mkzip
add mkzip class
2 parents f3ec704 + f7f241f commit 7835573

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

Qiniu/PFOP/Mkzip.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using Qiniu.Auth;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using Qiniu.RS;
7+
using Qiniu.RPC;
8+
using Qiniu.Conf;
9+
using Qiniu.Util;
10+
using Newtonsoft.Json;
11+
12+
namespace Qiniu.PFOP
13+
{
14+
public class Mkzip
15+
{
16+
17+
/// <summary>
18+
/// 多文件压缩存储为用户提供了批量文件的压缩存储功能
19+
/// POST /pfop/ HTTP/1.1
20+
/// Host: api.qiniu.com
21+
/// Content-Type: application/x-www-form-urlencoded
22+
/// Authorization: <AccessToken>
23+
/// bucket = <bucket>
24+
/// mkzip/<mode>
25+
/// /url/<Base64EncodedURL>
26+
/// /alias/<Base64EncodedAlias>
27+
/// /url/<Base64EncodedURL>
28+
/// ...
29+
/// </summary>
30+
public String doMkzip(String bucket, String existKey, String newFileName, String[] urls, string pipeline)
31+
{
32+
if (bucket == null || string.IsNullOrEmpty(existKey) || string.IsNullOrEmpty(newFileName) || urls.Length < 0 || pipeline == null)
33+
{
34+
throw new Exception("params error");
35+
}
36+
String entryURI = bucket + ":" + newFileName;
37+
String urlString = "";
38+
for (int i = 0; i < urls.Length; i++)
39+
{
40+
String urlEntry = "/url/" + Qiniu.Util.Base64URLSafe.ToBase64URLSafe(urls[i]);
41+
urlString += urlEntry;
42+
}
43+
String fop = System.Web.HttpUtility.UrlEncode("mkzip/1" + urlString + "|saveas/" + Qiniu.Util.Base64URLSafe.ToBase64URLSafe(entryURI));
44+
45+
string body = string.Format("bucket={0}&key={1}&fops={2}&pipeline={3}", bucket, existKey, fop, pipeline);
46+
47+
System.Text.Encoding curEncoding = System.Text.Encoding.UTF8;
48+
49+
QiniuAuthClient authClient = new QiniuAuthClient();
50+
CallRet ret = authClient.CallWithBinary(Config.API_HOST + "/pfop/", "application/x-www-form-urlencoded", StreamEx.ToStream(body), body.Length);
51+
if (ret.OK)
52+
{
53+
try
54+
{
55+
PersistentId pid = JsonConvert.DeserializeObject<PersistentId>(ret.Response);
56+
return pid.persistentId;
57+
}
58+
catch (Exception e)
59+
{
60+
throw e;
61+
}
62+
}
63+
else
64+
{
65+
throw new Exception(ret.Response);
66+
}
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)