I'm using Minio .Net SDK (v 3.1.13) in a web app to get buckets and files storage at IONOS Cloud Storage. It uses the AWS S3 specifications. I can check is a bucket exists and its contents, but just only the first time after compilation. Next times i get empty results.
S3ObjectStorage.cs
{
private MinioClient _minioClient;
public S3ObjectStorage(string key, string secret, string region, string httpsEndPoint) {
_minioClient = new MinioClient(httpsEndPoint, key, secret, region).WithSSL();
}
public async Task<bool> BucketExists(string bucketName) {
bool found = await _minioClient.BucketExistsAsync(bucketName);
return found;
}
public async Task<string> ListFiles(string bucketName, string path)
{
if (!await BucketExists(bucketName)) throw new Exception($"Buckect {bucketName} doesn't exists");
List<object> files = new List<object>();
IObservable<Item> observable = _minioClient.ListObjectsAsync(bucketName, path);
IDisposable subscription = observable.Subscribe(
item => files.Add(new { item.Key, item.Size })
//,ex => //Console.WriteLine($"OnError: {ex}")
);
return Newtonsoft.Json.JsonConvert.SerializeObject(files);
}
}```
TestS3.aspx.vb
```Private Async Function List(bucketName As String, path As String) As Task
Dim cs As New S3ObjectStorage(CS_KEY, CS_SECRET, CS_REGION, HTTPS_ENDPOINT)
Dim result As String = Await cs.ListFiles(bucketName, path)
Dim objects = Newtonsoft.Json.JsonConvert.DeserializeObject(result)
Me.rptObjetos.DataSource = objects
Me.rptObjetos.DataBind()
Me.lblPath.Text = $"{bucketName}>>{path} ({objects.Count} - {result})"
End Function```
Thanks a lot.
I got it!
using System.Reactive.Linq;
public async Task<string> ListFiles(string bucketName, string path)
{
if (!await BucketExists(bucketName)) throw new Exception($"Buckect {bucketName} doesn't exists");
var files = await _minioClient.ListObjectsAsync(bucketName, path).ToList();
return Newtonsoft.Json.JsonConvert.SerializeObject(files);
}