Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions Qiniu/Conf/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 帐户信息
Expand All @@ -26,7 +26,7 @@ public class Config
/// <summary>
/// 七牛资源上传服务器地址.
/// </summary>
public static string UP_HOST = "http://upload.qiniu.com";
public static string UP_HOST = "http://up.qiniu.com";
/// <summary>
/// 七牛资源列表服务器地址.
/// </summary>
Expand All @@ -44,15 +44,36 @@ public class Config
/// <summary>
/// 初始化七牛帐户、请求地址等信息,不应在客户端调用。
/// </summary>
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()
{
Expand Down
69 changes: 69 additions & 0 deletions Qiniu/PFOP/Mkzip.cs
Original file line number Diff line number Diff line change
@@ -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
{

/// <summary>
/// 多文件压缩存储为用户提供了批量文件的压缩存储功能
/// POST /pfop/ HTTP/1.1
/// Host: api.qiniu.com
/// Content-Type: application/x-www-form-urlencoded
/// Authorization: <AccessToken>
/// bucket = <bucket>
/// mkzip/<mode>
/// /url/<Base64EncodedURL>
/// /alias/<Base64EncodedAlias>
/// /url/<Base64EncodedURL>
/// ...
/// </summary>
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<PersistentId>(ret.Response);
return pid.persistentId;
}
catch (Exception e)
{
throw e;
}
}
else
{
throw new Exception(ret.Response);
}
}
}
}
47 changes: 36 additions & 11 deletions Qiniu/RS/RSClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,23 @@ public enum FileHandle
/// <summary>
/// 删除delete
/// </summary>
DELETE
DELETE,
/// <summary>
/// 抓取资源fetch
/// </summary>
FETCH
}

/// <summary>
/// 资源存储客户端,提供对文件的查看(stat),移动(move),复制(copy),删除(delete)操作
/// 资源存储客户端,提供对文件的查看(stat),移动(move),复制(copy),删除(delete), 抓取资源(fetch) 操作
/// 以及与这些操作对应的批量操作
/// </summary>
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)
{
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -125,6 +139,17 @@ public CallRet Copy (EntryPathPair pathPair)
return op2 (FileHandle.COPY, pathPair);
}

/// <summary>
/// 抓取资源
/// </summary>
/// <param name="fromUrl">需要抓取的文件URL</param>
/// <param name="entryPath">目标entryPath</param>
/// <returns>见<see cref="CallRet">CallRet</see></returns>
public CallRet Fetch(string fromUrl, EntryPath entryPath)
{
return opFetch(FileHandle.FETCH, fromUrl, entryPath);
}

/// <summary>
/// 获取一元批操作http request Body
/// </summary>
Expand Down Expand Up @@ -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);
}

/// <summary>
Expand Down