Skip to content

Instantly share code, notes, and snippets.

@uzbekdev1
Created December 19, 2025 17:41
Show Gist options
  • Select an option

  • Save uzbekdev1/ddfcfcb6d8650aca53378cb5b4a794ae to your computer and use it in GitHub Desktop.

Select an option

Save uzbekdev1/ddfcfcb6d8650aca53378cb5b4a794ae to your computer and use it in GitHub Desktop.
minio impl Amazon.S3 client
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("=====================================================");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment