diff --git a/README-CN.md b/README-CN.md deleted file mode 100644 index 70eeed8..0000000 --- a/README-CN.md +++ /dev/null @@ -1,125 +0,0 @@ -# Aliyun OSS SDK for C# - -[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) -[![GitHub version](https://badge.fury.io/gh/aliyun%2Faliyun-oss-csharp-sdk.svg)](https://badge.fury.io/gh/aliyun%2Faliyun-oss-csharp-sdk) -[![Build Status](https://travis-ci.org/aliyun/aliyun-oss-csharp-sdk.svg?branch=master)](https://travis-ci.org/aliyun/aliyun-oss-csharp-sdk) - -## [README of English](https://github.com/aliyun/aliyun-oss-csharp-sdk/blob/master/README.md) - -## 关于 - - 阿里云对象存储(Object Storage Service,OSS),是[阿里云](https://www.aliyun.com)对外提供的海量,安全,低成本,高可靠的云存储服务。 - - OSS C# SDK基于[OSS REST API](https://help.aliyun.com/document_detail/31948.html)构建。 - - OSS C# SDK[在线文档](http://gosspublic.alicdn.com/AliyunNetSDK/apidocs/latest/index.html)。 - -## 版本 - - 当前版本:2.9.1 - -## 运行环境 - -### Windows - - 适用于`.NET 2.0` 及以上版本 - - 适用于`Visual Studio 2010`及以上版本 - -### Linux/Mac - - 适用于`Mono 3.12` 及以上版本 - -## 安装方法 -### Windows环境安装 -#### NuGet安装 - - 如果您的Visual Studio没有安装NuGet,请先安装 [NuGet](http://docs.nuget.org/docs/start-here/installing-nuget). - - 安装好NuGet后,先在`Visual Studio`中新建或者打开已有的项目,然后选择`<工具>`-``-`<管理解决方案的NuGet程序包>`, - - 搜索`aliyun.oss.sdk`,在结果中找到`Aliyun.OSS.SDK`或`Aliyun.OSS.SDK.NetCore`,选择最新版本,点击安装,成功后添加到项目应用中。 - -#### GitHub安装 - - 如果没有安装git,请先安装 [git](https://git-scm.com/downloads) - - git clone https://github.com/aliyun/aliyun-oss-csharp-sdk.git - - 下载好源码后,按照`项目引入方式安装`即可 - -#### DLL引用方式安装 - - 从阿里云OSS官网下载SDK包,解压后bin目录包括了Aliyun.OSS.dll文件。 - - 在Visual Studio的`<解决方案资源管理器>`中选择您的项目,然后右键`<项目名称>`-`<引用>`,在弹出的菜单中选择`<添加引用>`, -在弹出`<添加引用>`对话框后,选择`<浏览>`,找到SDK包解压的目录,在bin目录下选中``文件,点击确定即可 - -#### 项目引入方式安装 - - 如果是下载了SDK包或者从GitHub上下载了源码,希望源码安装,可以右键`<解决方案>`,在弹出的菜单中点击`<添加>`->`<现有项目>`。 - - 在弹出的对话框中选择`aliyun-oss-sdk.csproj`文件,点击打开。 - - 接下来右键`<您的项目>`-`<引用>`,选择`<添加引用>`,在弹出的对话框选择`<项目>`选项卡后选中`aliyun-oss-sdk`项目,点击确定即可。 - -### Unix/Mac环境安装 -#### NuGet安装 - - 先在`Xamarin`中新建或者打开已有的项目,然后选择`<工具>`-``。 - - 搜索`aliyun.oss.sdk`,在结果中找到`Aliyun.OSS.SDK`,选择最新版本,点击``,成功后添加到项目应用中。 - -#### GitHub安装 - - 如果没有安装git,请先安装 [git](https://git-scm.com/downloads) - - git clone https://github.com/aliyun/aliyun-oss-csharp-sdk.git - - 下载好源码后,使用Xamarin打开,在Release模式下编译aliyun-oss-sdk项目,生成Aliyun.OSS.dll,然后通过DLL引用方式安装 - -#### DLL引用方式安装 - - 从阿里云OSS官网下载SDK包,解压后bin目录包括了Aliyun.OSS.dll文件。 - - 在Xamarin的`<解决方案>`中选择您的项目,然后右键`<项目名称>`-`<引用>`,在弹出的菜单中选择``, -在弹出``对话框后,选择`<.Net Assembly>-<浏览>`,找到SDK包解压的目录,在bin目录下选中``文件,点击``即可 - -## 快速使用 -#### 获取存储空间列表(List Bucket) -```csharp - OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); - var buckets = client.ListBuckets(); - - foreach (var bucket in buckets) - { - Console.WriteLine(bucket.Name + ", " + bucket.Location + ", " + bucket.Owner); - } -``` - -#### 创建存储空间(Create Bucket) -```csharp - OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); - client.CreateBucket(bucketName); -``` - -#### 删除存储空间(Delete Bucket) -```csharp - OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); - client.DeleteBucket(bucketName); -``` - -#### 上传文件(Put Object) -```csharp - OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); - client.PutObject(bucketName, key, filePathToUpload); -``` - -#### 下载文件 (Get Object) -```csharp - OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); - var object = ossClient.GetObject(bucketName, key); -``` - -#### 获取文件列表(List Objects) -```csharp - OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); - var listResult = client.ListObjects(bucketName); - foreach (var summary in listResult.ObjectSummaries) - { - Console.WriteLine(summary.Key); - } -``` - -#### 删除文件(Delete Object) -```csharp - OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); - client.DeleteObject(bucketName, key) -``` - -#### 其它 - - 上面的例子中,如果没有抛出异常则说明执行成功,否则失败,更详细的例子可以在aliyun-oss-sample项目中查看并运行。 - -## 注意事项 - - 如果要运行sample,需要将aliyun-oss-sdk-sample项目设为`启动项目`,并添加您自己的AccessKeyId,AccessKeySecret,bucket,key等后即可运行。 - -## 联系我们 -- [阿里云OSS官方网站](http://oss.aliyun.com) -- [阿里云OSS官方论坛](http://bbs.aliyun.com) -- [阿里云OSS官方文档中心](http://www.aliyun.com/product/oss#Docs) -- 阿里云官方技术支持:[提交工单](https://workorder.console.aliyun.com/#/ticket/createIndex) diff --git a/README.md b/README.md index 1f4ea2f..59b4f97 100644 --- a/README.md +++ b/README.md @@ -1,95 +1,79 @@ -# Alibaba Cloud OSS SDK for C# + +# Aliyun OSS SDK for C# [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) -[![GitHub Version](https://badge.fury.io/gh/aliyun%2Faliyun-oss-csharp-sdk.svg)](https://badge.fury.io/gh/aliyun%2Faliyun-oss-csharp-sdk) +[![GitHub version](https://badge.fury.io/gh/aliyun%2Faliyun-oss-csharp-sdk.svg)](https://badge.fury.io/gh/aliyun%2Faliyun-oss-csharp-sdk) [![Build Status](https://travis-ci.org/aliyun/aliyun-oss-csharp-sdk.svg?branch=master)](https://travis-ci.org/aliyun/aliyun-oss-csharp-sdk) -## [README of Chinese](https://github.com/aliyun/aliyun-oss-csharp-sdk/blob/master/README-CN.md) +## 补充功能 + - 增加阿里云OSS图片处理持久化功能 + - ![success](/doc/success.jpg) + - ![demo](/doc/demo.jpg) + - 原图:[https://itsvse.oss-cn-hangzhou.aliyuncs.com/test/itsvse.jpg](https://itsvse.oss-cn-hangzhou.aliyuncs.com/test/itsvse.jpg) + - 处理后:[https://itsvse.oss-cn-hangzhou.aliyuncs.com/test/itsvse_demo.jpg](https://itsvse.oss-cn-hangzhou.aliyuncs.com/test/itsvse_demo.jpg) + - [OSS图片处理6.0工具](https://gosspublic.alicdn.com/image/index.html) +#### 代码(Process Object) +```csharp + ProcessObjectSample.ProcessObject(bucketName, "test/itsvse.jpg", "image/watermark,type_d3F5LXplbmhlaQ,size_30,text_aHR0cHM6Ly93d3cuaXRzdnNlLmNvbS8,color_FF0000,t_90,g_se,x_10,y_10", "test/itsvse_demo.jpg"); +``` + -## About - Alibaba Cloud Object Storage Service (OSS) is a cloud storage service provided by [Alibaba Cloud](https://www.aliyun.com), featuring massive capacity, security, a low cost, and high reliability. - - The OSS C# SDK is built based on [OSS REST API](https://help.aliyun.com/document_detail/31948.html). - - OSS C# SDK[Online Documentation](http://gosspublic.alicdn.com/AliyunNetSDK/international/apidocs/latest/index.html). +## 关于 + - 阿里云对象存储(Object Storage Service,OSS),是[阿里云](https://www.aliyun.com)对外提供的海量,安全,低成本,高可靠的云存储服务。 + - OSS C# SDK基于[OSS REST API](https://help.aliyun.com/document_detail/31948.html)构建。 + - OSS C# SDK[在线文档](http://gosspublic.alicdn.com/AliyunNetSDK/apidocs/latest/index.html)。 -## Version - - Current version: 2.9.1. +## 版本 + - 当前版本:2.9.1 -## Run environment +## 运行环境 ### Windows - - Applicable to `.NET 2.0` or above. - - Applicable to `Visual Studio 2010` or above. + - 适用于`.NET 2.0` 及以上版本 + - 适用于`Visual Studio 2010`及以上版本 + ### Linux/Mac - - Applicable to `Mono 3.12` or above. -### .Net Core - - Applicable to `.net core 2.0` or above -## Install OSS C# SDK -### Install in Windows -#### Install the SDK through NuGet - - If NuGet hasn't been installed for Visual Studio, install [NuGet](http://docs.nuget.org/docs/start-here/installing-nuget) first. - - After NuGet is installed, access Visual Studio to create a project or open an existing project, and then select `TOOLS` > `NuGet Package Manager` > `Manage NuGet Packages for Solution`. - - Type `aliyun.oss.sdk` in the search box and click *Search*, find `Aliyun.OSS.SDK` or `Aliyun.OSS.SDK.NetCore` in the search results, select the latest version, and click *Install*. After installation, the SDK is added to the project. - -#### Install the SDK through GitHub - - If Git hasn't been installed, install [Git](https://git-scm.com/downloads) first. - - Clone project via `git clone https://github.com/aliyun/aliyun-oss-csharp-sdk.git`. - - After the source code is downloaded, install the SDK by entering `Install via Project Introduction`. - -#### Install the SDK through DLL reference - - Download the SDK packagefrom the Alibaba Cloud OSS official website. Unzip the package and you will find the ***Aliyun.OSS.dll*** file in the *bin* directory. - - In the Visual Studio, access `Solution Explorer`, select your project, right click *Project Name*, select `Add Reference` from the pop-up menu. -In the `Reference Manager` dialog box, click *Browse*, find the directory that the SDK is unzipped to, select the ***Aliyun.OSS.dll*** file in the *bin* directory, and click *OK*. - -#### Install the SDK through project introduction - - If you have downloaded the SDK package or the source code from GitHub and you want to install the SDK package using the source code, you can right click `Solution Explorer` and select `Add` > `Existing Projects` from the pop-up menu. - - In the pop-up dialog box, select the `aliyun-oss-sdk.csproj` file, and click *Open*. - - Right click *Your Projects* and select `Add Reference`. In the `Reference Manager` dialog box, click the `Projects` tab, select the ***aliyun-oss-sdk*** project, and click *OK*. - -### Install in Unix/Mac -#### Install the SDK through NuGet - - In `Xamarin`, create a project or open an existing project, and select `Tools` > `Add NuGet Packages`. - - Type `aliyun.oss.sdk` in the search box and click *Search*, find 'Aliyun.OSS.SDK' in the search results, select the latest version, and click `Add Package`. After installation, the SDK is added to the project. - -#### Install the SDK through GitHub - - If Git hasn't been installed, install [Git](https://git-scm.com/downloads) first. - - Clone project via `git clone https://github.com/aliyun/aliyun-oss-csharp-sdk.git`. - - After the source code is downloaded, open it in *Xamarin*. Compile the *aliyun-oss-sdk* project in ***Release*** mode to generate the `Aliyun.OSS.dll` file. Then install the SDK through *DLL reference*. - -#### Install the SDK through DLL reference - - Download the SDK package from Alibaba Cloud OSS official website. Unzip the package and you will find the ***Aliyun.OSS.dll*** file in the *bin* directory. - - In the Xamarin, access `Solution`, select your project, right click *Project Name*, select `Reference`' > `Edit References` from the pop-up menu. -In the `Edit References` dialog box, click `.Net Assembly` > `Browse`. Find the directory that the SDK is unzipped to, select the `Aliyun.OSS.dll` file in the *bin* directory, and click *Open*. -### Running with .Net core runtime -Starting with version 2.9, OSS SDK supports the .net core 2.0 platform. -#### Installing .Net core SDK & runtime -##### .Net Core SDK 2.0 (or above) -To build apps for .Net core 2.0, you need to install the .Net core 2.0 SDK. -Windows:https://www.microsoft.com/net/download/windows/build - -MacOS: https://www.microsoft.com/net/download/macos - -Linux: https://www.microsoft.com/net/download/linux/build - -##### .Net core runtime 2.0 (or above) -If you just want to run apps of .Net core 2.0, then you need to install the runtime: -Windows:https://www.microsoft.com/net/download/windows/run - -MacOS: https://www.microsoft.com/net/download/macos/run - -Linux: https://www.microsoft.com/net/download/linux/run - -#### Compile OSS SDK with .net core 2.0 - - cd to the root folder of OSS SDK. - - dotnet restore aliyun-oss-sdk-dotnetcore.sln - - dotnet build aliyun-oss-sdk-dotnetcore.sln - -#### To run Samples - - Update the samples\Config.cs to update the config properties with your actual OSS AKs and endpoint. - - use the step above to build the whole solution - - cd to the folder where Aliyun.OSS.Samples.dll exists and then run: `dotnet Aliyun.OSS.Samples.dll` - -## Quick use -#### Get the bucket list (List Bucket) + - 适用于`Mono 3.12` 及以上版本 + +## 安装方法 +### Windows环境安装 +#### NuGet安装 + - 如果您的Visual Studio没有安装NuGet,请先安装 [NuGet](http://docs.nuget.org/docs/start-here/installing-nuget). + - 安装好NuGet后,先在`Visual Studio`中新建或者打开已有的项目,然后选择`<工具>`-``-`<管理解决方案的NuGet程序包>`, + - 搜索`aliyun.oss.sdk`,在结果中找到`Aliyun.OSS.SDK`或`Aliyun.OSS.SDK.NetCore`,选择最新版本,点击安装,成功后添加到项目应用中。 + +#### GitHub安装 + - 如果没有安装git,请先安装 [git](https://git-scm.com/downloads) + - git clone https://github.com/aliyun/aliyun-oss-csharp-sdk.git + - 下载好源码后,按照`项目引入方式安装`即可 + +#### DLL引用方式安装 + - 从阿里云OSS官网下载SDK包,解压后bin目录包括了Aliyun.OSS.dll文件。 + - 在Visual Studio的`<解决方案资源管理器>`中选择您的项目,然后右键`<项目名称>`-`<引用>`,在弹出的菜单中选择`<添加引用>`, +在弹出`<添加引用>`对话框后,选择`<浏览>`,找到SDK包解压的目录,在bin目录下选中``文件,点击确定即可 + +#### 项目引入方式安装 + - 如果是下载了SDK包或者从GitHub上下载了源码,希望源码安装,可以右键`<解决方案>`,在弹出的菜单中点击`<添加>`->`<现有项目>`。 + - 在弹出的对话框中选择`aliyun-oss-sdk.csproj`文件,点击打开。 + - 接下来右键`<您的项目>`-`<引用>`,选择`<添加引用>`,在弹出的对话框选择`<项目>`选项卡后选中`aliyun-oss-sdk`项目,点击确定即可。 + +### Unix/Mac环境安装 +#### NuGet安装 + - 先在`Xamarin`中新建或者打开已有的项目,然后选择`<工具>`-``。 + - 搜索`aliyun.oss.sdk`,在结果中找到`Aliyun.OSS.SDK`,选择最新版本,点击``,成功后添加到项目应用中。 + +#### GitHub安装 + - 如果没有安装git,请先安装 [git](https://git-scm.com/downloads) + - git clone https://github.com/aliyun/aliyun-oss-csharp-sdk.git + - 下载好源码后,使用Xamarin打开,在Release模式下编译aliyun-oss-sdk项目,生成Aliyun.OSS.dll,然后通过DLL引用方式安装 + +#### DLL引用方式安装 + - 从阿里云OSS官网下载SDK包,解压后bin目录包括了Aliyun.OSS.dll文件。 + - 在Xamarin的`<解决方案>`中选择您的项目,然后右键`<项目名称>`-`<引用>`,在弹出的菜单中选择``, +在弹出``对话框后,选择`<.Net Assembly>-<浏览>`,找到SDK包解压的目录,在bin目录下选中``文件,点击``即可 + +## 快速使用 +#### 获取存储空间列表(List Bucket) ```csharp OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); var buckets = client.ListBuckets(); @@ -100,31 +84,31 @@ Linux: https://www.microsoft.com/net/download/linux/run } ``` -#### Create a bucket (Create Bucket) +#### 创建存储空间(Create Bucket) ```csharp OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); client.CreateBucket(bucketName); ``` -#### Delete a bucket (Delete Bucket) +#### 删除存储空间(Delete Bucket) ```csharp OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); client.DeleteBucket(bucketName); ``` -#### Upload a file (Put Object) +#### 上传文件(Put Object) ```csharp OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); client.PutObject(bucketName, key, filePathToUpload); ``` -#### Download an object (Get Object) +#### 下载文件 (Get Object) ```csharp OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); var object = ossClient.GetObject(bucketName, key); ``` -#### Get the object list (List Objects) +#### 获取文件列表(List Objects) ```csharp OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); var listResult = client.ListObjects(bucketName); @@ -134,20 +118,20 @@ Linux: https://www.microsoft.com/net/download/linux/run } ``` -#### Delete an object (Delete Object) +#### 删除文件(Delete Object) ```csharp OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); client.DeleteObject(bucketName, key) ``` -#### Others - - In the example above, if no exception was thrown, it indicates the execution was successful. Otherwise, it indicates the execution failed. More detailed examples can be found and run in the aliyun-oss-sample project. +#### 其它 + - 上面的例子中,如果没有抛出异常则说明执行成功,否则失败,更详细的例子可以在aliyun-oss-sample项目中查看并运行。 -## Notes - - If you want to run a sample project, you must set the aliyun-oss-sdk-sample project as the 'Startup Project' and add your own AccessKeyId, AccessKeySecret, buckets and keys, and then run the project. - -## Contact us -- [Alibaba Cloud OSS official website](http://oss.aliyun.com). -- [Alibaba Cloud OSS official forum](http://bbs.aliyun.com). -- [Alibaba Cloud OSS official documentation center](http://www.aliyun.com/product/oss#Docs). -- Alibaba Cloud official technical support: [Submit a ticket](https://workorder.console.aliyun.com/#/ticket/createIndex). +## 注意事项 + - 如果要运行sample,需要将aliyun-oss-sdk-sample项目设为`启动项目`,并添加您自己的AccessKeyId,AccessKeySecret,bucket,key等后即可运行。 + +## 联系我们 +- [阿里云OSS官方网站](http://oss.aliyun.com) +- [阿里云OSS官方论坛](http://bbs.aliyun.com) +- [阿里云OSS官方文档中心](http://www.aliyun.com/product/oss#Docs) +- 阿里云官方技术支持:[提交工单](https://workorder.console.aliyun.com/#/ticket/createIndex) diff --git a/doc/demo.jpg b/doc/demo.jpg new file mode 100644 index 0000000..5f3b84a Binary files /dev/null and b/doc/demo.jpg differ diff --git a/doc/success.jpg b/doc/success.jpg new file mode 100644 index 0000000..1c04c50 Binary files /dev/null and b/doc/success.jpg differ diff --git a/samples/Program.cs b/samples/Program.cs index f5d1ccb..b9133cf 100644 --- a/samples/Program.cs +++ b/samples/Program.cs @@ -16,7 +16,9 @@ public static void Main(string[] args) try { - CreateBucketSample.CreateBucket(bucketName); + ProcessObjectSample.ProcessObject(bucketName, "test/itsvse.jpg", "image/watermark,type_d3F5LXplbmhlaQ,size_30,text_aHR0cHM6Ly93d3cuaXRzdnNlLmNvbS8,color_FF0000,t_90,g_se,x_10,y_10", "test/itsvse_demo.jpg"); + + //CreateBucketSample.CreateBucket(bucketName); //ListBucketsSample.ListBuckets(); @@ -99,9 +101,9 @@ public static void Main(string[] args) //DeleteBucketSample.DeleteNoEmptyBucket(bucketName); //SetObjectAclSample.SetObjectAcl(bucketName); - + //GetObjectAclSample.GetBucketAcl(bucketName); - + //ImageProcessSample.ImageProcess(bucketName); //ProgressSample.Progress(bucketName); diff --git a/samples/Samples/ProcessObjectSample.cs b/samples/Samples/ProcessObjectSample.cs new file mode 100644 index 0000000..af77da5 --- /dev/null +++ b/samples/Samples/ProcessObjectSample.cs @@ -0,0 +1,30 @@ +using Aliyun.OSS.Common; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Aliyun.OSS.Samples +{ + public static class ProcessObjectSample + { + static string accessKeyId = Config.AccessKeyId; + static string accessKeySecret = Config.AccessKeySecret; + static string endpoint = Config.Endpoint; + static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); + + public static void ProcessObject(string bucketName, string key, string style, string o, string b =null) + { + try + { + client.ProcessObject(bucketName, key, style, o, b); + + Console.WriteLine("ProcessObject bucket name:{0} succeeded ", bucketName); + } + catch (OssException ex) + { + Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", + ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); + } + } + } +} diff --git a/samples/aliyun-oss-sdk-samples-dotnetcore.csproj b/samples/aliyun-oss-sdk-samples-dotnetcore.csproj index 0a638c3..021db7d 100644 --- a/samples/aliyun-oss-sdk-samples-dotnetcore.csproj +++ b/samples/aliyun-oss-sdk-samples-dotnetcore.csproj @@ -19,6 +19,7 @@ + diff --git a/sdk/Commands/OssCommand.cs b/sdk/Commands/OssCommand.cs index aac1503..7937ba2 100644 --- a/sdk/Commands/OssCommand.cs +++ b/sdk/Commands/OssCommand.cs @@ -122,14 +122,16 @@ private ServiceRequest BuildRequest() if (!Headers.ContainsKey(HttpHeaders.ContentType)) request.Headers[HttpHeaders.ContentType] = string.Empty; - - foreach(var h in Headers) + + if (Headers.ContainsKey("itsvse")) + request.Headers[HttpHeaders.ContentType] = Headers["itsvse"]; + + foreach (var h in Headers) request.Headers.Add(h.Key, h.Value); if (Context.Credentials.UseToken) request.Headers[HttpHeaders.SecurityToken] = Context.Credentials.SecurityToken; request.Content = Content; - return request; } } diff --git a/sdk/Commands/ProcessObjectCommand.cs b/sdk/Commands/ProcessObjectCommand.cs new file mode 100644 index 0000000..1cde485 --- /dev/null +++ b/sdk/Commands/ProcessObjectCommand.cs @@ -0,0 +1,99 @@ +using Aliyun.OSS.Common.Communication; +using Aliyun.OSS.Model; +using Aliyun.OSS.Transform; +using Aliyun.OSS.Util; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace Aliyun.OSS.Commands +{ + internal class ProcessObjectCommand : OssCommand + { + private readonly string _bucketName; + private readonly string _key; + private readonly string _style; + private readonly string _o; + private readonly string _b; + + protected override string Bucket + { + get { return _bucketName; } + } + + protected override string Key + { + get { return _key; } + } + + protected override HttpMethod Method + { + get { return HttpMethod.Post; } + } + + protected override IDictionary Parameters + { + get + { + var parameters = new Dictionary(); + parameters[RequestParameters.OSS_PROCESS] = null; + return parameters; + } + } + + protected override Stream Content + { + get + { + byte[] array = Encoding.ASCII.GetBytes("x-oss-process=" + string.Format("{0}|sys/saveas,o_{1}", _style, Encode(_o)) + _b ?? ("b_" + Encode(_b))); + MemoryStream stream = new MemoryStream(array); + return stream; + } + } + + protected override IDictionary Headers + { + get + { + var headers = new Dictionary(); + headers[HttpHeaders.ContentLength] = Content.Length.ToString(); + headers["itsvse"] = "application/x-www-form-urlencoded"; + return headers; + } + } + + /// + /// 字符串编码 + /// + /// 待编码的文本字符串 + /// 编码的文本字符串. + private static string Encode(string text) + { + var plainTextBytes = Encoding.UTF8.GetBytes(text); + var base64 = Convert.ToBase64String(plainTextBytes).Replace('+', '-').Replace('/', '_').TrimEnd('='); + return base64; + } + + private ProcessObjectCommand(IServiceClient client, Uri endpoint, ExecutionContext context, + string bucketName, string key, string style, string o, string b=null) + : base(client, endpoint, context) + { + OssUtils.CheckBucketName(bucketName); + OssUtils.CheckObjectKey(key); + + _bucketName = bucketName; + _key = key; + _style = style; + _o = o; + _b = b; + this.ParametersInUri = true; + } + + public static ProcessObjectCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, + string bucketName, string key, string style, string o, string b = null) + { + return new ProcessObjectCommand(client, endpoint, context, bucketName, key, style, o, b); + } + } +} diff --git a/sdk/Model/ProcessObjectResult.cs b/sdk/Model/ProcessObjectResult.cs new file mode 100644 index 0000000..59616ff --- /dev/null +++ b/sdk/Model/ProcessObjectResult.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Aliyun.OSS.Model +{ + public class ProcessObjectResult : GenericResult + { + } +} diff --git a/sdk/OssClient.cs b/sdk/OssClient.cs index ecf4859..5ab8d3d 100644 --- a/sdk/OssClient.cs +++ b/sdk/OssClient.cs @@ -1152,6 +1152,15 @@ public void DeleteObject(string bucketName, string key) } + public void ProcessObject(string bucketName, string key, string style, string o, string b = null) + { + var cmd = ProcessObjectCommand.Create(_serviceClient, _endpoint, + CreateContext(HttpMethod.Post, bucketName, key), + bucketName, key, style, o, b); + cmd.Execute(); + + } + /// public DeleteObjectsResult DeleteObjects(DeleteObjectsRequest deleteObjectsRequest) { diff --git a/sdk/Util/HttpHeaders.cs b/sdk/Util/HttpHeaders.cs index 2f721c4..28d3722 100644 --- a/sdk/Util/HttpHeaders.cs +++ b/sdk/Util/HttpHeaders.cs @@ -17,7 +17,7 @@ public static class HttpHeaders public const string ContentEncoding = "Content-Encoding"; public const string ContentLength = "Content-Length"; - + public const string ContentMd5 = "Content-MD5"; public const string ContentType = "Content-Type"; diff --git a/sdk/aliyun-oss-sdk-dotnetcore.csproj b/sdk/aliyun-oss-sdk-dotnetcore.csproj index d481cbb..88bc5a9 100644 --- a/sdk/aliyun-oss-sdk-dotnetcore.csproj +++ b/sdk/aliyun-oss-sdk-dotnetcore.csproj @@ -32,6 +32,7 @@ + @@ -81,6 +82,7 @@ + diff --git a/sdk/aliyun-oss-sdk.csproj b/sdk/aliyun-oss-sdk.csproj index 74e3d77..77ce414 100644 --- a/sdk/aliyun-oss-sdk.csproj +++ b/sdk/aliyun-oss-sdk.csproj @@ -146,6 +146,7 @@ + @@ -193,6 +194,7 @@ +