Steps to install and use MinIO in less than a minute ⏳ and managing objects using C# (AWS SDK for .NET)

Useme Alehosaini
4 min readNov 28, 2024

--

An Amazon S3 compatible object storage

MinIO is a high-performance, open-source object storage solution designed to store unstructured data like videos, images, backups, and more. It is fully compatible with the Amazon S3 API, which means you can use the same tools, libraries, and commands with MinIO that you would with AWS S3. MinIO is particularly suited for developers and organizations looking for a self-hosted, cost-effective, and highly scalable storage solution.

This article is going to include:

  • Why MinIO?!.
  • Steps to install MinIO with Docker.
  • C# Code Snippets (AWS SDK for .NET).

Why MinIO?!

  1. Private Object Storage: MinIO lets you host your own object storage system, giving you full control over your data.
  2. Cost-Efficiency: Unlike AWS S3, which charges for data transfer and storage, MinIO is free to use and runs on your existing infrastructure.
  3. High Performance: Optimized for high-throughput and low-latency applications, MinIO is an excellent choice for workloads like AI/ML, analytics, and edge computing.
  4. Scalability and Availability: MinIO scales horizontally with ease and offers robust replication capabilities to ensure high availability across data centers and regions.

Steps to install MinIO with Docker

Step 1: Install Docker (if not yet installed)
Install Docker Desktop for Windows, if it’s not already installed

Step 2: Start Docker Desktop
Start Docker Desktop and ensure it’s running before proceeding.

Step 3: Install MinIO
Using CLI command

docker run -p 9000:9000 -p 9001:9001 --name minio -e "MINIO_ROOT_USER=your-access-key" -e "MINIO_ROOT_PASSWORD=your-secret-key" -v /path/to/data:/data -v /path/to/config:/root/.minio  minio/minio server /data --console-address ":9001"

where:

  • -p 9000:9000: Exposes the MinIO API on port 9000.
  • -p 9001:9001: Exposes the MinIO web console on port 9001.
  • MINIO_ROOT_USER and MINIO_ROOT_PASSWORD: Set the admin credentials.
  • -v /path/to/data:/data: Maps storage to your local system for data persistence.
  • --console-address ":9001": Runs the MinIO web console on port 9001.

Response

PS C:\Windows\System32> docker run -p 9000:9000 -p 9001:9001 --name minio -e "MINIO_ROOT_USER=your-access-key" -e "MINIO_ROOT_PASSWORD=your-secret-key" -v /path/to/data:/data -v /path/to/config:/root/.minio  minio/minio server /data --console-address ":9001"
INFO: Formatting 1st pool, 1 set(s), 1 drives per set.
INFO: WARNING: Host local has more than 0 drives of set. A host failure will result in data becoming unavailable.
MinIO Object Storage Server
Copyright: 2015-2024 MinIO, Inc.
License: GNU AGPLv3 - https://www.gnu.org/licenses/agpl-3.0.html
Version: RELEASE.2024-11-07T00-52-20Z (go1.23.3 linux/amd64)

API: http://172.17.0.2:9000 http://127.0.0.1:9000
WebUI: http://172.17.0.2:9001 http://127.0.0.1:9001

Docs: https://docs.min.io

Which telling that MinIO is ready to be used and accessible via Web Console using http://127.0.0.1:9000 or http://localhost:9000

After filling the your-access-keyand your-secret-key you set and the clicking Login button, you are in and able to create a bucket.

click Object Browser, the bucket you created, and start upload files 😊

and here you go 😊 your files there.

and you can manage them.

C# Code Snippets

If you are using AWS SDK for .NET, here is some beneficial C# code snippets:


using Amazon.S3;
using Amazon.S3.Model;

AmazonS3Client s3Client = CreateS3Client();

await UploadFile(s3Client);

await ListAllObjects(s3Client);

await DownloadObject(s3Client);

await UpdateObject(s3Client); // Overwrite

await DeleteObject(s3Client);

await ListAllObjects(s3Client);

static AmazonS3Client CreateS3Client()
{
var s3Config = new AmazonS3Config
{
ServiceURL = "http://localhost:9000", // MinIO URL
ForcePathStyle = true // Required for MinIO compatibility
};

return new AmazonS3Client("your-access-key", "your-secret-key", s3Config);
}

static async Task UploadFile(AmazonS3Client s3Client)
{
var putRequest = new PutObjectRequest
{
BucketName = "my-bucket",
Key = "my-object.txt",
FilePath = @"C:\repos\Testfiles\my-object.txt" //"path/to/your/file.txt"
};

await s3Client.PutObjectAsync(putRequest);

await Console.Out.WriteLineAsync("File has been uploaded");
await Console.Out.WriteLineAsync("=====================================================");
}

static async Task ListAllObjects(AmazonS3Client s3Client)
{
var listRequest = new ListObjectsV2Request
{
BucketName = "my-bucket"
};

var listResponse = await s3Client.ListObjectsV2Async(listRequest);

await Console.Out.WriteLineAsync("All objects in S3");
await Console.Out.WriteLineAsync("-----------------------------------------------------");

foreach (var obj in listResponse.S3Objects)
{
await Console.Out.WriteLineAsync($"Object: {obj.Key}, Size: {obj.Size}");
}

await Console.Out.WriteLineAsync("=====================================================");
}

static async Task DownloadObject(AmazonS3Client s3Client)
{
var getRequest = new GetObjectRequest
{
BucketName = "my-bucket",
Key = "my-object.txt"
};

using (var response = await s3Client.GetObjectAsync(getRequest))
using (var reader = new StreamReader(response.ResponseStream))
{
string content = await reader.ReadToEndAsync();
await Console.Out.WriteLineAsync("Object has been downloaded");
await Console.Out.WriteLineAsync($"Object Content: {content}");
await Console.Out.WriteLineAsync("=====================================================");
}
}

static async Task UpdateObject(AmazonS3Client s3Client)
{
var updateRequest = new PutObjectRequest
{
BucketName = "my-bucket",
Key = "my-object.txt",
ContentBody = "Updated Content!"
};

await s3Client.PutObjectAsync(updateRequest);
await Console.Out.WriteLineAsync("Object has been updated");
await Console.Out.WriteLineAsync("=====================================================");
}

static async Task DeleteObject(AmazonS3Client s3Client)
{
var deleteRequest = new DeleteObjectRequest
{
BucketName = "my-bucket",
Key = "my-object.txt"
};

await s3Client.DeleteObjectAsync(deleteRequest);
await Console.Out.WriteLineAsync("Object has been deleted");
await Console.Out.WriteLineAsync("=====================================================");
}

and the result should be

File has been uploaded
=====================================================
All objects in S3
-----------------------------------------------------
Object: developer.jpg, Size: 98117
Object: my-object.txt, Size: 22
=====================================================
Object has been downloaded
Object Content: This is a test content
=====================================================
Object has been updated
=====================================================
Object has been deleted
=====================================================
All objects in S3
-----------------------------------------------------
Object: developer.jpg, Size: 98117
=====================================================

Done 😊

💡 Please let me know your opinion in the comments.

Thank you for your time 😊

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Useme Alehosaini
Useme Alehosaini

Written by Useme Alehosaini

A Lifelong learner, passionate about self-improvement, soft skills, technology and finance. LinkedIn https://www.linkedin.com/in/useme-mba-msc/

No responses yet

Write a response