diff --git a/Qiniu/Conf/Config.cs b/Qiniu/Conf/Config.cs
index e5892c81..949eb6fc 100644
--- a/Qiniu/Conf/Config.cs
+++ b/Qiniu/Conf/Config.cs
@@ -5,7 +5,7 @@ namespace Qiniu.Conf
{
public class Config
{
- public static string VERSION = "6.1.4";
+ public static string VERSION = "6.1.5";
public static string USER_AGENT = getUa();
#region 帐户信息
@@ -26,7 +26,7 @@ public class Config
///
/// 七牛资源上传服务器地址.
///
- public static string UP_HOST = "http://upload.qiniu.com";
+ public static string UP_HOST = "http://up.qiniu.com";
///
/// 七牛资源列表服务器地址.
///
@@ -44,15 +44,36 @@ public class Config
///
/// 初始化七牛帐户、请求地址等信息,不应在客户端调用。
///
- public static void Init()
+ public static void Init()
{
- USER_AGENT = System.Configuration.ConfigurationManager.AppSettings["USER_AGENT"];
- ACCESS_KEY = System.Configuration.ConfigurationManager.AppSettings["ACCESS_KEY"];
- SECRET_KEY = System.Configuration.ConfigurationManager.AppSettings["SECRET_KEY"];
- RS_HOST = System.Configuration.ConfigurationManager.AppSettings["RS_HOST"];
- UP_HOST = System.Configuration.ConfigurationManager.AppSettings["UP_HOST"];
- RSF_HOST = System.Configuration.ConfigurationManager.AppSettings["RSF_HOST"];
- PREFETCH_HOST = System.Configuration.ConfigurationManager.AppSettings["PREFETCH_HOST"];
+ if (System.Configuration.ConfigurationManager.AppSettings["USER_AGENT"] != null)
+ {
+ USER_AGENT = System.Configuration.ConfigurationManager.AppSettings["USER_AGENT"];
+ }
+ if (System.Configuration.ConfigurationManager.AppSettings["ACCESS_KEY"] != null)
+ {
+ ACCESS_KEY = System.Configuration.ConfigurationManager.AppSettings["ACCESS_KEY"];
+ }
+ if (System.Configuration.ConfigurationManager.AppSettings["SECRET_KEY"] != null)
+ {
+ SECRET_KEY = System.Configuration.ConfigurationManager.AppSettings["SECRET_KEY"];
+ }
+ if (System.Configuration.ConfigurationManager.AppSettings["RS_HOST"] != null)
+ {
+ RS_HOST = System.Configuration.ConfigurationManager.AppSettings["RS_HOST"];
+ }
+ if (System.Configuration.ConfigurationManager.AppSettings["UP_HOST"] != null)
+ {
+ UP_HOST = System.Configuration.ConfigurationManager.AppSettings["UP_HOST"];
+ }
+ if (System.Configuration.ConfigurationManager.AppSettings["RSF_HOST"] != null)
+ {
+ RSF_HOST = System.Configuration.ConfigurationManager.AppSettings["RSF_HOST"];
+ }
+ if (System.Configuration.ConfigurationManager.AppSettings["PREFETCH_HOST"] != null)
+ {
+ PREFETCH_HOST = System.Configuration.ConfigurationManager.AppSettings["PREFETCH_HOST"];
+ }
}
private static string getUa()
{
diff --git a/Qiniu/PFOP/Mkzip.cs b/Qiniu/PFOP/Mkzip.cs
new file mode 100644
index 00000000..71a3be4f
--- /dev/null
+++ b/Qiniu/PFOP/Mkzip.cs
@@ -0,0 +1,69 @@
+using Qiniu.Auth;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Qiniu.RS;
+using Qiniu.RPC;
+using Qiniu.Conf;
+using Qiniu.Util;
+using Newtonsoft.Json;
+
+namespace Qiniu.PFOP
+{
+ public class Mkzip
+ {
+
+ ///
+ /// 多文件压缩存储为用户提供了批量文件的压缩存储功能
+ /// POST /pfop/ HTTP/1.1
+ /// Host: api.qiniu.com
+ /// Content-Type: application/x-www-form-urlencoded
+ /// Authorization:
+ /// bucket =
+ /// mkzip/
+ /// /url/
+ /// /alias/
+ /// /url/
+ /// ...
+ ///
+ public String doMkzip(String bucket, String existKey, String newFileName, String[] urls, string pipeline)
+ {
+ if (bucket == null || string.IsNullOrEmpty(existKey) || string.IsNullOrEmpty(newFileName) || urls.Length < 0 || pipeline == null)
+ {
+ throw new Exception("params error");
+ }
+ String entryURI = bucket + ":" + newFileName;
+ String urlString = "";
+ for (int i = 0; i < urls.Length; i++)
+ {
+ String urlEntry = "/url/" + Qiniu.Util.Base64URLSafe.ToBase64URLSafe(urls[i]);
+ urlString += urlEntry;
+ }
+ String fop = System.Web.HttpUtility.UrlEncode("mkzip/1" + urlString + "|saveas/" + Qiniu.Util.Base64URLSafe.ToBase64URLSafe(entryURI));
+
+ string body = string.Format("bucket={0}&key={1}&fops={2}&pipeline={3}", bucket, existKey, fop, pipeline);
+
+ System.Text.Encoding curEncoding = System.Text.Encoding.UTF8;
+
+ QiniuAuthClient authClient = new QiniuAuthClient();
+ CallRet ret = authClient.CallWithBinary(Config.API_HOST + "/pfop/", "application/x-www-form-urlencoded", StreamEx.ToStream(body), body.Length);
+ if (ret.OK)
+ {
+ try
+ {
+ PersistentId pid = JsonConvert.DeserializeObject(ret.Response);
+ return pid.persistentId;
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ }
+ else
+ {
+ throw new Exception(ret.Response);
+ }
+ }
+ }
+}
diff --git a/Qiniu/RS/RSClient.cs b/Qiniu/RS/RSClient.cs
index 4d3a1a04..a2d2048b 100644
--- a/Qiniu/RS/RSClient.cs
+++ b/Qiniu/RS/RSClient.cs
@@ -29,19 +29,23 @@ public enum FileHandle
///
/// 删除delete
///
- DELETE
+ DELETE,
+ ///
+ /// 抓取资源fetch
+ ///
+ FETCH
}
///
- /// 资源存储客户端,提供对文件的查看(stat),移动(move),复制(copy),删除(delete)操作
+ /// 资源存储客户端,提供对文件的查看(stat),移动(move),复制(copy),删除(delete), 抓取资源(fetch) 操作
/// 以及与这些操作对应的批量操作
///
- public class RSClient :QiniuAuthClient
+ public class RSClient : QiniuAuthClient
{
- private static string[] OPS = new string[] { "stat", "move", "copy", "delete" };
+ private static string[] OPS = new string[] { "stat", "move", "copy", "delete", "fetch" };
- public RSClient (Mac mac=null)
- : base(mac)
+ public RSClient(Mac mac = null)
+ : base(mac)
{
}
@@ -73,6 +77,16 @@ private CallRet op2 (FileHandle op, EntryPathPair pair)
OPS [(int)op],
Base64URLSafe.Encode (pair.URISrc),
Base64URLSafe.Encode (pair.URIDest));
+ return Call(url);
+ }
+
+ private CallRet opFetch(FileHandle op, string fromUrl, EntryPath entryPath)
+ {
+ string url = string.Format("{0}/{1}/{2}/to/{3}",
+ Config.RS_HOST,
+ OPS[(int)op],
+ Base64URLSafe.Encode(fromUrl),
+ Base64URLSafe.Encode(entryPath.URI));
return Call (url);
}
@@ -125,6 +139,17 @@ public CallRet Copy (EntryPathPair pathPair)
return op2 (FileHandle.COPY, pathPair);
}
+ ///
+ /// 抓取资源
+ ///
+ /// 需要抓取的文件URL
+ /// 目标entryPath
+ /// 见CallRet
+ public CallRet Fetch(string fromUrl, EntryPath entryPath)
+ {
+ return opFetch(FileHandle.FETCH, fromUrl, entryPath);
+ }
+
///
/// 获取一元批操作http request Body
///
@@ -168,11 +193,11 @@ OPS [(int)op],
Base64URLSafe.Encode (keys [keys.Length - 1].URISrc),
Base64URLSafe.Encode (keys [keys.Length - 1].URIDest));
return sb.Append (litem).ToString ();
- }
-
- private CallRet batch(string requestBody)
- {
- return CallWithBinary(Conf.Config.RS_HOST + "/batch", "application/x-www-form-urlencoded", StreamEx.ToStream(requestBody), requestBody.Length);
+ }
+
+ private CallRet batch(string requestBody)
+ {
+ return CallWithBinary(Conf.Config.RS_HOST + "/batch", "application/x-www-form-urlencoded", StreamEx.ToStream(requestBody), requestBody.Length);
}
///