You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
8.4 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. # MinIO Client SDK for .NET [![Slack](https://slack.min.io/slack?type=svg)](https://slack.min.io) [![Build status](https://ci.appveyor.com/api/projects/status/tvdpoypdmbuwg0me/branch/master?svg=true)](https://ci.appveyor.com/project/Harshavardhana/minio-dotnet/branch/master)
  2. MinIO Client SDK provides higher level APIs for MinIO and Amazon S3 compatible cloud storage services.For a complete list of APIs and examples, please take a look at the [Dotnet Client API Reference](https://docs.min.io/docs/dotnet-client-api-reference).This document assumes that you have a working VisualStudio development environment.
  3. ## Minimum Requirements
  4. * .NET 4.5.2, .NetStandard 2.0 or higher
  5. * Visual Studio 2017
  6. ## Install from NuGet
  7. To install [MinIO .NET package](https://www.nuget.org/packages/Minio/), run the following command in Nuget Package Manager Console.
  8. ```powershell
  9. PM> Install-Package Minio
  10. ```
  11. ## MinIO Client Example
  12. To connect to an Amazon S3 compatible cloud storage service, you will need to specify the following parameters.
  13. | Parameter | Description|
  14. | :--- | :--- |
  15. | endpoint | URL to object storage service. |
  16. | accessKey | Access key is the user ID that uniquely identifies your account. |
  17. | secretKey | Secret key is the password to your account. |
  18. | secure | Enable/Disable HTTPS support. |
  19. The following examples uses a freely hosted public MinIO service 'play.min.io' for development purposes.
  20. ```cs
  21. using Minio;
  22. // Initialize the client with access credentials.
  23. private static MinioClient minio = new MinioClient("play.min.io",
  24. "Q3AM3UQ867SPQQA43P2F",
  25. "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
  26. ).WithSSL();
  27. // Create an async task for listing buckets.
  28. var getListBucketsTask = minio.ListBucketsAsync();
  29. // Iterate over the list of buckets.
  30. foreach (Bucket bucket in getListBucketsTask.Result.Buckets)
  31. {
  32. Console.WriteLine(bucket.Name + " " + bucket.CreationDateDateTime);
  33. }
  34. ```
  35. ## Complete _File Uploader_ Example
  36. This example program connects to an object storage server, creates a bucket and uploads a file to the bucket.
  37. To run the following example, click on [Link] and start the project
  38. ```cs
  39. using System;
  40. using Minio;
  41. using Minio.Exceptions;
  42. using Minio.DataModel;
  43. using System.Threading.Tasks;
  44. namespace FileUploader
  45. {
  46. class FileUpload
  47. {
  48. static void Main(string[] args)
  49. {
  50. var endpoint = "play.min.io";
  51. var accessKey = "Q3AM3UQ867SPQQA43P2F";
  52. var secretKey = "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG";
  53. try
  54. {
  55. var minio = new MinioClient(endpoint, accessKey, secretKey).WithSSL();
  56. FileUpload.Run(minio).Wait();
  57. }
  58. catch (Exception ex)
  59. {
  60. Console.WriteLine(ex.Message);
  61. }
  62. Console.ReadLine();
  63. }
  64. // File uploader task.
  65. private async static Task Run(MinioClient minio)
  66. {
  67. var bucketName = "mymusic";
  68. var location = "us-east-1";
  69. var objectName = "golden-oldies.zip";
  70. var filePath = "C:\\Users\\username\\Downloads\\golden_oldies.mp3";
  71. var contentType = "application/zip";
  72. try
  73. {
  74. // Make a bucket on the server, if not already present.
  75. bool found = await minio.BucketExistsAsync(bucketName);
  76. if (!found)
  77. {
  78. await minio.MakeBucketAsync(bucketName, location);
  79. }
  80. // Upload a file to bucket.
  81. await minio.PutObjectAsync(bucketName, objectName, filePath, contentType);
  82. Console.WriteLine("Successfully uploaded " + objectName );
  83. }
  84. catch (MinioException e)
  85. {
  86. Console.WriteLine("File Upload Error: {0}", e.Message);
  87. }
  88. }
  89. }
  90. }
  91. ```
  92. ## Running MinIO Client Examples
  93. #### On Windows
  94. * Clone this repository and open the Minio.Sln in Visual Studio 2017.
  95. * Enter your credentials and bucket name, object name etc.in Minio.Examples/Program.cs
  96. Uncomment the example test cases such as below in Program.cs to run an example.
  97. ```cs
  98. //Cases.MakeBucket.Run(minioClient, bucketName).Wait();
  99. ```
  100. * Run the Minio.Client.Examples project from Visual Studio
  101. #### On Linux (Ubuntu 16.04)
  102. ##### Setting up Mono and .NETCore on Linux
  103. <blockquote> NOTE: minio-dotnet requires mono 5.0.1 stable release and .NET Core 2.0 SDK to build on Linux. </blockquote>
  104. * Install [.NETCore](https://www.microsoft.com/net/core#linuxredhat) and [Mono](http://www.mono-project.com/download/#download-lin) for your distro. See sample script to install .NETCore and Mono for Ubuntu Xenial [mono_install.sh](https://github.com/minio/minio-dotnet/blob/master/mono_install.sh)
  105. ```
  106. $ ./mono_install.sh
  107. ```
  108. ##### Running Minio.Examples
  109. * Clone this project.
  110. ```
  111. $ git clone https://github.com/minio/minio-dotnet && cd minio-dotnet
  112. ```
  113. * Enter your credentials and bucket name, object name etc. in Minio.Examples/Program.cs
  114. Uncomment the example test cases such as below in Program.cs to run an example.
  115. ```cs
  116. //Cases.MakeBucket.Run(minioClient, bucketName).Wait();
  117. ```
  118. ```
  119. $ cd Minio.Examples
  120. $ dotnet build -c Release
  121. $ dotnet run
  122. ```
  123. #### Bucket Operations
  124. * [MakeBucket.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/MakeBucket.cs)
  125. * [ListBuckets.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/ListBuckets.cs)
  126. * [BucketExists.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/BucketExists.cs)
  127. * [RemoveBucket.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/RemoveBucket.cs)
  128. * [ListObjects.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/ListObjects.cs)
  129. * [ListIncompleteUploads.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/ListIncompleteUploads.cs)
  130. #### Bucket policy Operations
  131. * [GetPolicy.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/GetBucketPolicy.cs)
  132. * [SetPolicy.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/SetBucketPolicy.cs)
  133. #### Bucket notification Operations
  134. * [GetBucketNotification.cs](./Minio.Examples/Cases/GetBucketNotification.cs)
  135. * [SetBucketNotification.cs](./Minio.Examples/Cases/SetBucketNotification.cs)
  136. * [RemoveAllBucketNotifications.cs](./Minio.Examples/Cases/RemoveAllBucketNotifications.cs)
  137. #### File Object Operations
  138. * [FGetObject.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/FGetObject.cs)
  139. * [FPutObject.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/FPutObject.cs)
  140. #### Object Operations
  141. * [GetObject.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/GetObject.cs)
  142. * [GetPartialObject.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/GetPartialObject.cs)
  143. * [PutObject.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/PutObject.cs)
  144. * [StatObject.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/StatObject.cs)
  145. * [RemoveObject.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/RemoveObject.cs)
  146. * [RemoveObjects.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/RemoveObjects.cs)
  147. * [CopyObject.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/CopyObject.cs)
  148. * [CopyObject.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/CopyObjectMetadata.cs)
  149. * [RemoveIncompleteUpload.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/RemoveIncompleteUpload.cs)
  150. #### Presigned Operations
  151. * [PresignedGetObject.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/PresignedGetObject.cs)
  152. * [PresignedPutObject.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/PresignedPutObject.cs)
  153. * [PresignedPostPolicy.cs](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Cases/PresignedPostPolicy.cs)
  154. #### Client Custom Settings
  155. * [SetAppInfo](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Program.cs)
  156. * [SetTraceOn](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Program.cs)
  157. * [SetTraceOff](https://github.com/minio/minio-dotnet/blob/master/Minio.Examples/Program.cs)
  158. ## Explore Further
  159. * [Complete Documentation](https://docs.min.io)
  160. * [MinIO .NET SDK API Reference](https://docs.min.io/docs/dotnet-client-api-reference)