I'm trying to get filenames within a bucket of my MinIO server using the ListObjectsAsync method.
Here is the relevant code:
public async Task<string> GetFileName(string userID, string datasetID)
{
ListObjectsArgs args = new ListObjectsArgs()
.WithBucket(userID)
.WithPrefix(datasetID)
.WithRecursive(true);
var files = _minio.ListObjectsAsync(args);
List<string> fileNames = new();
IDisposable subscription = files
.Subscribe(item =>
fileNames.Add(item.Key),
() => Console.WriteLine(fileNames.Count)
);
// I want to return one of the filenames here!
return "";
}
The code above fills the list fileNames as expected and prints out the correct number of files within the respective locations. However, I would like to user the data within the function above.
I know I could do the following:
files.ToList().Wait();
However, this is a blocking call. Should I simply wrap this call into Task or is there some other (better) way to get the required data?