question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[not our bug] how to use ListObjectsAsync?

See original GitHub issue

Good morning.

I am using Minio (dotnet) SDK 3.0.2 but this case is also the same in (the current) 3.0.8 version.

Since the SDK does not provide anything easy like that I tried my self to implement a function that returns a list of all keys in a bucket (at the given time it is called).

It looks like that (well, one problem is that the command line tool does not have async methods):

  public List<string> GetMinioBucketKeys()
  {
    List<string> bucketKeys = new List<string>();
    IObservable<Minio.DataModel.Item> observable = _minio.ListObjectsAsync(_minioBucketName);
    IDisposable subscription = observable.Subscribe
    (
      item => bucketKeys.Add(item.Key),                                                       // onNext
      ex => throw new Exception("GetMinioBucketKeys subscription raised an exception", ex),   // onError
      () => Log($"GetMinioBucketKeys completed and collected {bucketKeys.Count} bucket keys") // onCompleted
    );
    subscription.Dispose();
    return bucketKeys;
  }

I ensured (at the initialization of minio client) that the bucket exists. I uploaded two files and expected to get a list with the two bucket keys. I received an empty list.

In order to evaluate what I am doing wrong I took your ListObjects example and tested it using it as:

Minio.Examples.Cases.ListObjects.Run(_minio, "test", null, true);

The result is the same. No files are detected. Tested with 3.0.2 and 3.0.8.

The single log line in the console is “Running example for API: ListObjectsAsync”. I would at least miss the line “Listed all objects in bucket test” written on OnCompleted in the sample.

Is this some bug (since the official code samples too do not detect any files in the bucket)?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

21reactions
poornascommented, Mar 25, 2019

you will need to await the observable if you want to collect the items into a list as ListObjectsAsync is an async operation

using System.Reactive.Linq;  <====
...
public static ICollection<string> ListFiles(Minio.MinioClient minio,
                                     string bucketName = "test",
                                     string prefix = null,
                                     bool recursive = true)
        {
            try
            {

                List<string> bucketKeys = new List<string>();

                IObservable<Item> observable = minio.ListObjectsAsync(bucketName, prefix, recursive);

                IDisposable subscription = observable.Subscribe
                (
                    item => bucketKeys.Add(item.Key),
                    ex => throw ex
                );
                observable.Wait();                           <=====
                //subscription.Dispose();

                return bucketKeys;
            }
            catch (Exception)
            {
                throw;
            }

        }

1reaction
MontyGvMCcommented, Mar 27, 2019

That was it. Thank you very much.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve Access Denied error for ListObjectsV2 using S3 sync
I'm running the aws s3 sync command to copy objects to or from an Amazon Simple Storage Service (Amazon S3) bucket. However, I'm...
Read more >
How do I get a list of strings from an observable.Subscribe ...
I got the C# .net core ListObjectsAsync example working for Minio: , but how do I capture the results into a List instead...
Read more >
Listing object keys programmatically
Use the Amazon S3 list operation to select and browse object keys hierarchically.
Read more >
.NET Client API Reference — MinIO Object Storage for Linux
To use non-anonymous access, chain method WithCredentials() to the client object along with the access key & secret key. Finally chain the method...
Read more >
Error in deleting objects using AWS s3 SDK
I use AWS s3 sdk to interact with storj. ... If it does show objects but the S3 interface says no objects exist,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found