diff --git a/.gitignore b/.gitignore index f31b3e29..9082a585 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ -.DS_Store -*.swp +.DS_Store +*.swp +*.suo + +bin +obj \ No newline at end of file diff --git a/Example/RSDemo.cs b/Demo/Demo.cs old mode 100755 new mode 100644 similarity index 58% rename from Example/RSDemo.cs rename to Demo/Demo.cs index adf84bbd..ca1adce3 --- a/Example/RSDemo.cs +++ b/Demo/Demo.cs @@ -1,14 +1,11 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Diagnostics; using QBox.Auth; using QBox.RS; +using QBox.FileOp; -namespace QBox.Example +namespace QBox.Demo { - public class RSDemo + public class Demo { public static string bucketName; public static string key; @@ -16,6 +13,7 @@ public class RSDemo public static string DEMO_DOMAIN; public static Client conn; public static RSService rs; + public static ImageOp imageOp; public static void Main() { @@ -23,16 +21,15 @@ public static void Main() Config.SECRET_KEY = ""; bucketName = "csharpbucket"; - DEMO_DOMAIN = "iovip.qbox.me/csharpbucket"; + DEMO_DOMAIN = "csharpbucket.dn.qbox.me"; + localFile = "Resource/gogopher.jpg"; + key = "gogopher.jpg"; + conn = new DigestAuthClient(); rs = new RSService(conn, bucketName); - localFile = Process.GetCurrentProcess().MainModule.FileName; - key = System.IO.Path.GetFileName(localFile); - - CallRet callRet = rs.MkBucket(); - PrintRet(callRet); + imageOp = new ImageOp(conn); - RSPutFile(); + MkBucket(); RSClientPutFile(); Get(); Stat(); @@ -41,9 +38,21 @@ public static void Main() Delete(); Drop(); + MkBucket(); + RSPutFile(); + Publish(); + ImageOps(); + Console.ReadLine(); } + public static void MkBucket() + { + Console.WriteLine("\n===> RSService.MkBucket"); + CallRet callRet = rs.MkBucket(); + PrintRet(callRet); + } + public static void RSPutFile() { Console.WriteLine("\n===> RSService.PutFile"); @@ -199,6 +208,94 @@ public static void UnPublish() } } + public static void ImageOps() + { + Console.WriteLine("\n===> ImageInfo"); + ImageInfoRet infoRet = imageOp.ImageInfo("http://" + DEMO_DOMAIN + "/" + key); + PrintRet(infoRet); + if (infoRet.OK) + { + Console.WriteLine("Format: " + infoRet.Format); + Console.WriteLine("Width: " + infoRet.Width); + Console.WriteLine("Heigth: " + infoRet.Height); + Console.WriteLine("ColorModel: " + infoRet.ColorModel); + } + else + { + Console.WriteLine("Failed to ImageInfo"); + } + + Console.WriteLine("\n===> ImageExif"); + CallRet exifRet = imageOp.ImageExif("http://" + DEMO_DOMAIN + "/" + key); + PrintRet(exifRet); + if (!exifRet.OK) + { + Console.WriteLine("Failed to ImageExif"); + } + + Console.WriteLine("\n===> ImageViewUrl"); + ImageViewSpec viewSpec = new ImageViewSpec{Mode = 0, Width = 200, Height= 200}; + string viewUrl = imageOp.ImageViewUrl("http://" + DEMO_DOMAIN + "/" + key, viewSpec); + Console.WriteLine("ImageViewUrl 1:" + viewUrl); + viewSpec.Quality = 1; + viewSpec.Format = "gif"; + viewUrl = imageOp.ImageViewUrl("http://" + DEMO_DOMAIN + "/" + key, viewSpec); + Console.WriteLine("ImageViewUrl 2:" + viewUrl); + viewSpec.Quality = 90; + viewSpec.Sharpen = 10; + viewSpec.Format = "png"; + viewUrl = imageOp.ImageViewUrl("http://" + DEMO_DOMAIN + "/" + key, viewSpec); + Console.WriteLine("ImageViewUrl 3:" + viewUrl); + + Console.WriteLine("\n===> ImageMogrifyUrl"); + ImageMogrifySpec mogrSpec = new ImageMogrifySpec { + Thumbnail = "!50x50r", Gravity = "center", Rotate = 90, + Crop = "!50x50", Quality = 80, AutoOrient = true + }; + string mogrUrl = imageOp.ImageMogrifyUrl("http://" + DEMO_DOMAIN + "/" + key, mogrSpec); + Console.WriteLine("ImageMogrifyUrl:" + mogrUrl); + + Console.WriteLine("\n===> Get"); + GetRet getRet = rs.Get(key, "save-as"); + PrintRet(getRet); + if (getRet.OK) + { + Console.WriteLine("Hash: " + getRet.Hash); + Console.WriteLine("FileSize: " + getRet.FileSize); + Console.WriteLine("MimeType: " + getRet.MimeType); + Console.WriteLine("Url: " + getRet.Url); + } + else + { + Console.WriteLine("Failed to Get"); + } + Console.WriteLine("\n===> ImageMogrifySaveAs"); + PutFileRet saveAsRet = rs.ImageMogrifySaveAs(getRet.Url, mogrSpec, key + ".mogr-save-as"); + PrintRet(saveAsRet); + if (saveAsRet.OK) + { + Console.WriteLine("Hash: " + saveAsRet.Hash); + } + else + { + Console.WriteLine("Failed to ImageMogrifySaveAs"); + } + Console.WriteLine("\n===> Get"); + getRet = rs.Get(key + ".mogr-save-as", "mogr-save-as.jpg"); + PrintRet(getRet); + if (getRet.OK) + { + Console.WriteLine("Hash: " + getRet.Hash); + Console.WriteLine("FileSize: " + getRet.FileSize); + Console.WriteLine("MimeType: " + getRet.MimeType); + Console.WriteLine("Url: " + getRet.Url); + } + else + { + Console.WriteLine("Failed to Get"); + } + } + public static void PrintRet(CallRet callRet) { Console.WriteLine("\n[CallRet]"); diff --git a/Demo/Demo.csproj b/Demo/Demo.csproj new file mode 100644 index 00000000..abb28ab4 --- /dev/null +++ b/Demo/Demo.csproj @@ -0,0 +1,61 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {8BA368D7-3784-4C50-9A28-4FA1A9C81555} + Exe + Properties + Demo + Demo + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + Always + + + + + + + + {1C8C9909-57ED-44E4-81A5-0904E96FA00E} + QBox + + + + + + + + \ No newline at end of file diff --git a/Demo/Resource/gogopher.jpg b/Demo/Resource/gogopher.jpg new file mode 100644 index 00000000..12c4dab3 Binary files /dev/null and b/Demo/Resource/gogopher.jpg differ diff --git a/QBox/Auth/AuthPolicy.cs b/QBox/Auth/AuthPolicy.cs old mode 100755 new mode 100644 diff --git a/QBox/Auth/DigestAuthClient.cs b/QBox/Auth/DigestAuthClient.cs old mode 100755 new mode 100644 diff --git a/Docs/README.md b/QBox/Docs/README.md similarity index 81% rename from Docs/README.md rename to QBox/Docs/README.md index ff7a00c8..58c45b18 100644 --- a/Docs/README.md +++ b/QBox/Docs/README.md @@ -1,200 +1,179 @@ ---- -title: C# SDK | 七牛云存储 ---- - -# C# SDK 使用指南 - - -此 SDK 适用于 .NET4 及以上版本。 - -SDK下载地址:[https://github.com/qiniu/csharp-sdk/tags](https://github.com/qiniu/csharp-sdk/tags) - - -**应用接入** - -- [获取 Access Key 和 Secret Key](#acc-appkey) -- [签名认证](#acc-auth) - -**云存储接口** - -- [新建资源表](#rs-NewService) -- [上传文件](#rs-PutFile) - - [服务器端上传](#server-PutFile) - - [客户端使用授权URL上传](#client-PutFile) - - [客户端使用UpToken上传](#client-PutFileWithUpToke) -- [获取已上传文件信息](#rs-Stat) -- [下载文件](#rs-Get) -- [发布公开资源](#rs-Publish) -- [取消资源发布](#rs-Unpublish) -- [删除已上传的文件](#rs-Delete) -- [删除整张资源表](#rs-Drop) - -## 应用接入 - - - -### 1. 获取Access Key 和 Secret Key - -要接入七牛云存储,您需要拥有一对有效的 Access Key 和 Secret Key 用来进行签名认证。可以通过如下步骤获得: - -1. [开通七牛开发者帐号](https://dev.qiniutek.com/signup) -2. [登录七牛开发者自助平台,查看 Access Key 和 Secret Key](https://dev.qiniutek.com/account/keys) 。 - - - -### 2. 签名认证 - -首先,到 [https://github.com/qiniu/csharp-sdk](https://github.com/qiniu/csharp-sdk) 下载SDK源码。 - -然后,将 SDK 导入到您的 Visual C# 项目中,并编辑 QBox 目录下的 Config.cs 文件,确保其包含您从七牛开发者平台所获取的 [Access Key 和 Secret Key](#acc-appkey): - - public static string ACCESS_KEY = ""; - public static string SECRET_KEY = ""; - -在完成 Access Key 和 Secret Key 配置后,为了正常使用该 SDK 提供的功能,您还需要使用你获得的 Access Key 和 Secret Key 向七牛云存储服务器发出认证请求: - - DigestAuthClient conn = new DigestAuthClient(); - -请求成功后得到的 conn 即可用于您正常使用七牛云存储的一系列功能,接下来将一一介绍。 - -## 云存储接口 - - - -### 1. 新建资源表 - - // 首先定义资源表名 - string tableName = "tableName"; - - // 然后获得签名认证 - DigestAuthClient conn = new DigestAuthClient(); - - // 签名认证完成后,即可使用该认证来新建资源表 - RSService rs = new RSService(conn, tableName); - CallRet callRet = rs.MkBucket(); - - - -### 2. 上传文件 - -七牛云存储上传文件的方式分为服务器端上传和客户端上传两种。 - - - -##### 2.1 服务器端上传 - - // 调用资源表对象的 PutFile() 方法进行文件上传 - PutFileRet putFileRet = rs.PutFile(key, mimeType, filePath, customMeta); - - - -##### 2.2 客户端使用授权URL上传 - -###### 2.2.1 获取经过授权的临时URL - -客户端上传文件之前需要取得上传授权,可以是一个临时有效URL。 - - // 调用资源表对象的 putAuth() 方法来获取授权的临时URL - PutAuthRet putAuthRet = rs.PutAuth(); - uploadUrl = putAuthRet.Url; - -如果请求成功,putAuthRet 会包含 Url 和 Expires 两个字段。Url 字段对应的值为匿名上传的临时 URL,Expires 对应的值则是该临时 URL 的有效期。 - -###### 2.2.2 使用临时URL上传文件 - - // 通过该临时 URL 进行文件上传 - PutFileRet putFileRet = RSClient.PutFile(uploadUrl, tableName, key, mimeType, - filePath, customMeta, callbackParam); - - - -##### 2.3 客户端使用UpToken上传 - -###### 2.3.1 生成用于上传文件的临时凭证UpToken - -客户端上传文件之前需要取得上传授权,可以一个 UpToken,UpToken 是服务器端颁发给客户端的上传凭证,参数 expires 对应的值则是该 UpToken 的有效期。 - - // 生成 UpToken - var authPolicy = new AuthPolicy(tabletName, expires); - string upToken = authPolicy.MakeAuthTokenString(); - -###### 2.3.2 使用UpToken上传文件 - - // 使用 UpToken 上传文件 - PutFileRet putFileRet = RSClient.PutFileWithUpToken( - upToken, tableName, key, mimeType, - filePath, customMeta, callbackParam); - - - -### 3. 获取已上传文件信息 - -您可以调用资源表对象的 Stat() 方法并传入一个 Key 来获取指定文件的相关信息。 - - // 获取资源表中特定文件信息 - StatRet statRet = rs.Stat(key); - -如果请求成功,得到的 statRet 将会包含如下几个字段: - - Hash: - FileSize: - PutTime: - MimeType: - - - -### 4. 下载文件 - -要下载一个文件,首先需要取得下载授权,所谓下载授权,就是取得一个临时合法有效的下载链接,只需传入相应的文件 Key 和下载要保存的文件名作为参数即可。 - - // 下载资源表中的特定文件 - GetRet getRet = rs.Get(key, filename); - GetRet getRet = rs.GetIfNotModified(key, filename, baseHash); - -返回的 getRet 包含如下字段: - - Url: # 获取文件内容的实际下载地址 - Hash: - FileSize: - MimeType: - -方法 GetIfNotModified 与 Get 的不同之处在于多了一个 baseHash 参数。这个参数是一个 SHA-1 值,用于判断所指向的文件内容是否被改动。只有在内容没有被变动时才会返回该文件的下载URL。 - - - -### 5. 发布公开资源 - -使用七牛云存储提供的资源发布功能,您可以将一个资源表里边的所有文件以静态链接可访问的方式公开发布到您自己的域名下。 - -要公开发布一个资源表里边的所有文件,只需调用该资源表对象的 Publish() 方法并传入域名作为参数即可。 - - // 公开发布某个资源表 - CallRet publishRet = rs.Publish(DomainName); - - - -### 6. 取消资源发布 - -调用资源表对象的 Unpublish() 方法可取消该资源表内所有文件的静态外链。 - - // 取消公开发布某个资源表 - CallRet unpublishRet = rs.Unpublish(DomainName); - - - -### 7. 删除已上传的文件 - -要删除指定的文件,只需调用资源表对象的 Delete() 方法并传入文件 key 作为参数即可。 - - // 删除资源表中的某个文件 - CallRet deleteRet = rs.Delete(key); - - - -### 8. 删除整张资源表 - -要删除整个资源表及该表里边的所有文件,可以调用资源表对象的 Drop() 方法。 -需慎重,这会删除整个表及其所有文件。 - - // 删除整个资源表 - CallRet dropRet = rs.Drop(); +--- +title: C# SDK | 七牛云存储 +--- + +# C# SDK 使用指南 + + +此 SDK 适用于 .NET4 及以上版本。 + +SDK下载地址:[https://github.com/qiniu/csharp-sdk/tags](https://github.com/qiniu/csharp-sdk/tags) + + +**应用接入** + +- [获取 Access Key 和 Secret Key](#acc-appkey) +- [签名认证](#acc-auth) + +**云存储接口** + +- [新建资源表](#rs-NewService) +- [上传文件](#rs-PutFile) + - [服务器端上传](#server-PutFile) + - [客户端上传](#client-PutFileWithUpToke) +- [获取已上传文件信息](#rs-Stat) +- [下载文件](#rs-Get) +- [发布公开资源](#rs-Publish) +- [取消资源发布](#rs-Unpublish) +- [删除已上传的文件](#rs-Delete) +- [删除整张资源表](#rs-Drop) + +## 应用接入 + + + +### 1. 获取Access Key 和 Secret Key + +要接入七牛云存储,您需要拥有一对有效的 Access Key 和 Secret Key 用来进行签名认证。可以通过如下步骤获得: + +1. [开通七牛开发者帐号](https://dev.qiniutek.com/signup) +2. [登录七牛开发者自助平台,查看 Access Key 和 Secret Key](https://dev.qiniutek.com/account/keys) 。 + + + +### 2. 签名认证 + +首先,到 [https://github.com/qiniu/csharp-sdk](https://github.com/qiniu/csharp-sdk) 下载SDK源码。 + +然后,将 SDK 导入到您的 Visual C# 项目中,并编辑 QBox 目录下的 Config.cs 文件,确保其包含您从七牛开发者平台所获取的 [Access Key 和 Secret Key](#acc-appkey): + + public static string ACCESS_KEY = ""; + public static string SECRET_KEY = ""; + +在完成 Access Key 和 Secret Key 配置后,为了正常使用该 SDK 提供的功能,您还需要使用你获得的 Access Key 和 Secret Key 向七牛云存储服务器发出认证请求: + + DigestAuthClient conn = new DigestAuthClient(); + +请求成功后得到的 conn 即可用于您正常使用七牛云存储的一系列功能,接下来将一一介绍。 + +## 云存储接口 + + + +### 1. 新建资源表 + + // 首先定义资源表名 + string tableName = "tableName"; + + // 然后获得签名认证 + DigestAuthClient conn = new DigestAuthClient(); + + // 签名认证完成后,即可使用该认证来新建资源表 + RSService rs = new RSService(conn, tableName); + CallRet callRet = rs.MkBucket(); + + + +### 2. 上传文件 + +七牛云存储上传文件的方式分为服务器端上传和客户端上传两种。 + + + +#### 2.1 服务器端上传 + + // 调用资源表对象的 PutFile() 方法进行文件上传 + PutFileRet putFileRet = rs.PutFile(key, mimeType, filePath, customMeta); + + + +#### 2.2 客户端上传 + +##### 2.2.1 生成用于上传文件的临时凭证UpToken + +客户端上传文件之前需要取得上传授权 UpToken,UpToken 是服务器端颁发给客户端的上传凭证,参数 expires 对应的值则是该 UpToken 的有效期。 + + // 生成 UpToken + var authPolicy = new AuthPolicy(tabletName, expires); + string upToken = authPolicy.MakeAuthTokenString(); + +##### 2.2.2 使用UpToken上传文件 + + // 使用 UpToken 上传文件 + PutFileRet putFileRet = RSClient.PutFileWithUpToken( + upToken, tableName, key, mimeType, + filePath, customMeta, callbackParam); + + + +### 3. 获取已上传文件信息 + +您可以调用资源表对象的 Stat() 方法并传入一个 Key 来获取指定文件的相关信息。 + + // 获取资源表中特定文件信息 + StatRet statRet = rs.Stat(key); + +如果请求成功,得到的 statRet 将会包含如下几个字段: + + Hash: + FileSize: + PutTime: + MimeType: + + + +### 4. 下载文件 + +要下载一个文件,首先需要取得下载授权,所谓下载授权,就是取得一个临时合法有效的下载链接,只需传入相应的文件 Key 和下载要保存的文件名作为参数即可。 + + // 下载资源表中的特定文件 + GetRet getRet = rs.Get(key, filename); + GetRet getRet = rs.GetIfNotModified(key, filename, baseHash); + +返回的 getRet 包含如下字段: + + Url: # 获取文件内容的实际下载地址 + Hash: + FileSize: + MimeType: + +方法 GetIfNotModified 与 Get 的不同之处在于多了一个 baseHash 参数。这个参数是一个 SHA-1 值,用于判断所指向的文件内容是否被改动。只有在内容没有被变动时才会返回该文件的下载URL。 + + + +### 5. 发布公开资源 + +使用七牛云存储提供的资源发布功能,您可以将一个资源表里边的所有文件以静态链接可访问的方式公开发布到您自己的域名下。 + +要公开发布一个资源表里边的所有文件,只需调用该资源表对象的 Publish() 方法并传入域名作为参数即可。 + + // 公开发布某个资源表 + CallRet publishRet = rs.Publish(DomainName); + + + +### 6. 取消资源发布 + +调用资源表对象的 Unpublish() 方法可取消该资源表内所有文件的静态外链。 + + // 取消公开发布某个资源表 + CallRet unpublishRet = rs.Unpublish(DomainName); + + + +### 7. 删除已上传的文件 + +要删除指定的文件,只需调用资源表对象的 Delete() 方法并传入文件 key 作为参数即可。 + + // 删除资源表中的某个文件 + CallRet deleteRet = rs.Delete(key); + + + +### 8. 删除整张资源表 + +要删除整个资源表及该表里边的所有文件,可以调用资源表对象的 Drop() 方法。 +需慎重,这会删除整个表及其所有文件。 + + // 删除整个资源表 + CallRet dropRet = rs.Drop(); diff --git a/QBox/FileOp/ImageInfoRet.cs b/QBox/FileOp/ImageInfoRet.cs new file mode 100644 index 00000000..64b52ee9 --- /dev/null +++ b/QBox/FileOp/ImageInfoRet.cs @@ -0,0 +1,40 @@ +using System; +using QBox.RS; +using LitJson; + +namespace QBox.FileOp +{ + public class ImageInfoRet : CallRet + { + public string Format { get; private set; } + public int Width { get; private set; } + public int Height { get; private set; } + public string ColorModel { get; private set; } + + public ImageInfoRet(CallRet ret) + : base(ret) + { + if (!String.IsNullOrEmpty(Response)) + { + try + { + Unmarshal(Response); + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + this.Exception = e; + } + } + } + + private void Unmarshal(string json) + { + JsonData data = JsonMapper.ToObject(json); + Format = (string)data["format"]; + Width = (int)data["width"]; + Height = (int)data["height"]; + ColorModel = (string)data["colorModel"]; + } + } +} diff --git a/QBox/FileOp/ImageMogrifySpec.cs b/QBox/FileOp/ImageMogrifySpec.cs new file mode 100644 index 00000000..338f26e7 --- /dev/null +++ b/QBox/FileOp/ImageMogrifySpec.cs @@ -0,0 +1,35 @@ +using System; + +namespace QBox.FileOp +{ + public class ImageMogrifySpec + { + public string Thumbnail { get; set; } + public string Gravity { get; set; } + public string Crop { get; set; } + public int Quality { get; set; } + public int Rotate { get; set; } + public string Format { get; set; } + public bool AutoOrient { get; set; } + + public string MakeSpecString() + { + string spec = "?imageMogr"; + if (!String.IsNullOrEmpty(Thumbnail)) + spec += "/thumbnail/" + Thumbnail; + if (!String.IsNullOrEmpty(Gravity)) + spec += "/gravity/" + Gravity; + if (!String.IsNullOrEmpty(Crop)) + spec += "/crop/" + Crop; + if (Quality != 0) + spec += "/quality/" + Quality.ToString(); + if (Rotate != 0) + spec += "/rotate/" + Rotate.ToString(); + if (!String.IsNullOrEmpty(Format)) + spec += "/format/" + Format; + if (AutoOrient) + spec += "/auto-orient"; + return spec; + } + } +} diff --git a/QBox/FileOp/ImageOp.cs b/QBox/FileOp/ImageOp.cs new file mode 100644 index 00000000..02b83e3b --- /dev/null +++ b/QBox/FileOp/ImageOp.cs @@ -0,0 +1,36 @@ +using System; +using QBox.RS; + +namespace QBox.FileOp +{ + public class ImageOp + { + public Client Conn { get; private set; } + + public ImageOp(Client conn) + { + Conn = conn; + } + + public ImageInfoRet ImageInfo(string url) + { + CallRet callRet = Conn.Call(url + "?imageInfo"); + return new ImageInfoRet(callRet); + } + + public CallRet ImageExif(string url) + { + return Conn.Call(url + "?exif"); + } + + public string ImageViewUrl(string url, ImageViewSpec spec) + { + return url + spec.MakeSpecString(); + } + + public string ImageMogrifyUrl(string url, ImageMogrifySpec spec) + { + return url + spec.MakeSpecString(); + } + } +} diff --git a/QBox/FileOp/ImageViewSpec.cs b/QBox/FileOp/ImageViewSpec.cs new file mode 100644 index 00000000..df05bd28 --- /dev/null +++ b/QBox/FileOp/ImageViewSpec.cs @@ -0,0 +1,30 @@ +using System; + +namespace QBox.FileOp +{ + public class ImageViewSpec + { + public int Mode { get; set; } + public int Width { get; set; } + public int Height { get; set; } + public int Quality { get; set; } + public string Format { get; set; } + public int Sharpen { get; set; } + + public string MakeSpecString() + { + string spec = "?imageView/" + Mode.ToString(); + if (Width != 0) + spec += "/w/" + Width.ToString(); + if (Height != 0) + spec += "/h/" + Height.ToString(); + if (Quality != 0) + spec += "/q/" + Quality.ToString(); + if (!String.IsNullOrEmpty(Format)) + spec += "/format/" + Format; + if (Sharpen != 0) + spec += "/sharpen/" + Sharpen; + return spec; + } + } +} diff --git a/Json/IJsonWrapper.cs b/QBox/Json/IJsonWrapper.cs old mode 100755 new mode 100644 similarity index 100% rename from Json/IJsonWrapper.cs rename to QBox/Json/IJsonWrapper.cs diff --git a/Json/JsonData.cs b/QBox/Json/JsonData.cs old mode 100755 new mode 100644 similarity index 100% rename from Json/JsonData.cs rename to QBox/Json/JsonData.cs diff --git a/Json/JsonException.cs b/QBox/Json/JsonException.cs old mode 100755 new mode 100644 similarity index 100% rename from Json/JsonException.cs rename to QBox/Json/JsonException.cs diff --git a/Json/JsonMapper.cs b/QBox/Json/JsonMapper.cs old mode 100755 new mode 100644 similarity index 100% rename from Json/JsonMapper.cs rename to QBox/Json/JsonMapper.cs diff --git a/Json/JsonReader.cs b/QBox/Json/JsonReader.cs old mode 100755 new mode 100644 similarity index 100% rename from Json/JsonReader.cs rename to QBox/Json/JsonReader.cs diff --git a/Json/JsonWriter.cs b/QBox/Json/JsonWriter.cs old mode 100755 new mode 100644 similarity index 100% rename from Json/JsonWriter.cs rename to QBox/Json/JsonWriter.cs diff --git a/Json/Lexer.cs b/QBox/Json/Lexer.cs old mode 100755 new mode 100644 similarity index 100% rename from Json/Lexer.cs rename to QBox/Json/Lexer.cs diff --git a/Json/ParserToken.cs b/QBox/Json/ParserToken.cs old mode 100755 new mode 100644 similarity index 100% rename from Json/ParserToken.cs rename to QBox/Json/ParserToken.cs diff --git a/QBox/Properties/AssemblyInfo.cs b/QBox/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..cc843a76 --- /dev/null +++ b/QBox/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("QBox")] +[assembly: AssemblyDescription("csharp-sdk")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Qiniu Information Technologies")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f036fae6-2ac0-4b5a-8e66-60220f1b8c6c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/QBox/QBox.csproj b/QBox/QBox.csproj new file mode 100644 index 00000000..86714eec --- /dev/null +++ b/QBox/QBox.csproj @@ -0,0 +1,84 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {1C8C9909-57ED-44E4-81A5-0904E96FA00E} + Library + Properties + QBox + QBox + v4.0 + + + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/QBox/RS/Base64UrlSafe.cs b/QBox/RS/Base64UrlSafe.cs old mode 100755 new mode 100644 diff --git a/QBox/RS/CallRet.cs b/QBox/RS/CallRet.cs old mode 100755 new mode 100644 diff --git a/QBox/RS/Client.cs b/QBox/RS/Client.cs old mode 100755 new mode 100644 index 3ef28c61..7c0ba38e --- a/QBox/RS/Client.cs +++ b/QBox/RS/Client.cs @@ -4,9 +4,9 @@ namespace QBox.RS { - public abstract class Client + public class Client { - public abstract void SetAuth(HttpWebRequest request, Stream body); + public virtual void SetAuth(HttpWebRequest request, Stream body) { } public CallRet Call(string url) { diff --git a/QBox/RS/Config.cs b/QBox/RS/Config.cs old mode 100755 new mode 100644 diff --git a/QBox/RS/FileParameter.cs b/QBox/RS/FileParameter.cs old mode 100755 new mode 100644 diff --git a/QBox/RS/GetRet.cs b/QBox/RS/GetRet.cs old mode 100755 new mode 100644 diff --git a/QBox/RS/MultiPartFormDataPost.cs b/QBox/RS/MultiPartFormDataPost.cs old mode 100755 new mode 100644 diff --git a/QBox/RS/PutAuthRet.cs b/QBox/RS/PutAuthRet.cs old mode 100755 new mode 100644 diff --git a/QBox/RS/PutFileRet.cs b/QBox/RS/PutFileRet.cs old mode 100755 new mode 100644 diff --git a/QBox/RS/RSClient.cs b/QBox/RS/RSClient.cs old mode 100755 new mode 100644 diff --git a/QBox/RS/RSService.cs b/QBox/RS/RSService.cs old mode 100755 new mode 100644 index 6e3a0950..891649b9 --- a/QBox/RS/RSService.cs +++ b/QBox/RS/RSService.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Net; +using QBox.FileOp; namespace QBox.RS { @@ -76,8 +77,8 @@ public GetRet GetIfNotModified(string key, string attName, string hash) public StatRet Stat(string key) { - String entryURI = BucketName + ":" + key; - String url = Config.RS_HOST + "/stat/" + Base64UrlSafe.Encode(entryURI); + string entryURI = BucketName + ":" + key; + string url = Config.RS_HOST + "/stat/" + Base64UrlSafe.Encode(entryURI); CallRet callRet = Conn.Call(url); return new StatRet(callRet); } @@ -106,5 +107,19 @@ public CallRet Drop() string url = Config.RS_HOST + "/drop/" + BucketName; return Conn.Call(url); } + + public PutFileRet SaveAs(string url, string specStr, string key) + { + string entryURI = BucketName + ":" + key; + url = url + specStr + "/save-as/" + Base64UrlSafe.Encode(entryURI); + CallRet callRet = Conn.Call(url); + return new PutFileRet(callRet); + } + + public PutFileRet ImageMogrifySaveAs(string url, ImageMogrifySpec spec, string key) + { + string specStr = spec.MakeSpecString(); + return SaveAs(url, specStr, key); + } } } diff --git a/QBox/RS/StatRet.cs b/QBox/RS/StatRet.cs old mode 100755 new mode 100644 diff --git a/QBox/app.config b/QBox/app.config new file mode 100644 index 00000000..cb2586be --- /dev/null +++ b/QBox/app.config @@ -0,0 +1,3 @@ + + + diff --git a/README.md b/README.md index 17eb4c04..c2ce1131 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,27 @@ -# Qiniu Resource (Cloud) Storage SDK for C# - -# 关于 - -此 C# SDK 适用于 .NET4 及以上版本,基于 [七牛云存储官方API](http://docs.qiniutek.com/v2/api/) 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个网站程序,还是包括从云端(服务端程序)到终端(手持设备应用)的架构的服务或应用,通过七牛云存储及其 SDK,都能让您应用程序的终端用户高速上传和下载,同时也让您的服务端更加轻盈。 - -## 使用 - -参考文档:[七牛云存储 C# SDK 使用指南](http://docs.qiniutek.com/v2/sdk/csharp/) - -## 贡献代码 - -1. Fork -2. 创建您的特性分支 (`git checkout -b my-new-feature`) -3. 提交您的改动 (`git commit -am 'Added some feature'`) -4. 将您的修改记录提交到远程 `git` 仓库 (`git push origin my-new-feature`) -5. 然后到 github 网站的该 `git` 远程仓库的 `my-new-feature` 分支下发起 Pull Request - -## 许可证 - -Copyright (c) 2012 qiniutek.com - -基于 MIT 协议发布: - -* [www.opensource.org/licenses/MIT](http://www.opensource.org/licenses/MIT) - - +# Qiniu Resource (Cloud) Storage SDK for C# + +# 关于 + +此 C# SDK 适用于 .NET4 及以上版本,基于 [七牛云存储官方API](http://docs.qiniutek.com/v2/api/) 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个网站程序,还是包括从云端(服务端程序)到终端(手持设备应用)的架构的服务或应用,通过七牛云存储及其 SDK,都能让您应用程序的终端用户高速上传和下载,同时也让您的服务端更加轻盈。 + +## 使用 + +参考文档:[七牛云存储 C# SDK 使用指南](http://docs.qiniutek.com/v2/sdk/csharp/) + +## 贡献代码 + +1. Fork +2. 创建您的特性分支 (`git checkout -b my-new-feature`) +3. 提交您的改动 (`git commit -am 'Added some feature'`) +4. 将您的修改记录提交到远程 `git` 仓库 (`git push origin my-new-feature`) +5. 然后到 github 网站的该 `git` 远程仓库的 `my-new-feature` 分支下发起 Pull Request + +## 许可证 + +Copyright (c) 2012 qiniutek.com + +基于 MIT 协议发布: + +* [www.opensource.org/licenses/MIT](http://www.opensource.org/licenses/MIT) + + diff --git a/csharp-sdk.sln b/csharp-sdk.sln new file mode 100644 index 00000000..2ad0e386 --- /dev/null +++ b/csharp-sdk.sln @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C# Express 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QBox", "QBox\QBox.csproj", "{1C8C9909-57ED-44E4-81A5-0904E96FA00E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo", "Demo\Demo.csproj", "{8BA368D7-3784-4C50-9A28-4FA1A9C81555}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1C8C9909-57ED-44E4-81A5-0904E96FA00E}.Debug|x86.ActiveCfg = Debug|x86 + {1C8C9909-57ED-44E4-81A5-0904E96FA00E}.Debug|x86.Build.0 = Debug|x86 + {1C8C9909-57ED-44E4-81A5-0904E96FA00E}.Release|x86.ActiveCfg = Release|x86 + {1C8C9909-57ED-44E4-81A5-0904E96FA00E}.Release|x86.Build.0 = Release|x86 + {8BA368D7-3784-4C50-9A28-4FA1A9C81555}.Debug|x86.ActiveCfg = Debug|x86 + {8BA368D7-3784-4C50-9A28-4FA1A9C81555}.Debug|x86.Build.0 = Debug|x86 + {8BA368D7-3784-4C50-9A28-4FA1A9C81555}.Release|x86.ActiveCfg = Release|x86 + {8BA368D7-3784-4C50-9A28-4FA1A9C81555}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal