Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to list object in an S3 regional bucket #673

Closed
anthonyMc11 opened this issue Aug 10, 2022 · 2 comments
Closed

Unable to list object in an S3 regional bucket #673

anthonyMc11 opened this issue Aug 10, 2022 · 2 comments

Comments

@anthonyMc11
Copy link
Contributor

anthonyMc11 commented Aug 10, 2022

I am using the following code:

` class Program
{
static async Task Main()
{
var bucket = "my-bucket-name";
var filePrefix = "379c05ee-d204-4dc7-b26b-66ad8f9e68d4/";

        var _mediaClient = new MinioClient().WithEndpoint("s3.amazonaws.com").WithCredentials("myaccesskey",
            "mysecretkey").WithSSL().WithRegion("eu-west-2").Build();

        var exists = await _mediaClient.BucketExistsAsync(bucket);

        if (exists)
        {
            ListObjectsArgs args = new ListObjectsArgs().WithPrefix(filePrefix).WithRecursive(true)
                .WithBucket(bucket).WithListObjectsV1(false);
            IObservable<Item> observable = _mediaClient.ListObjectsAsync(args);
            var files = await observable.Select(item => item.Key).ToList();
            foreach (var file in files)
            {
                Console.WriteLine(file);
            }
        }
    }
}`

I am getting a perminent redirect error when the observable.Select(item => item.Key).ToList(); runs. I have diagnosed this to the to line 299 of the minioclient.cs

if (!string.IsNullOrEmpty(objectName) && method != HttpMethod.Put) region = await GetRegion(bucketName).ConfigureAwait(false);

because I'm doing a list operation, the objectName is null and I'm not doing a Put request, therefore the region isn't loaded, and causes the above error.

I have rebuilt the code without this check and loaded the region and the code now works as expected, however this has broken a unit test TestInvalidObjectNameError()

Could you please assist as I can't list my objects, thank you

@anthonyMc11
Copy link
Contributor Author

anthonyMc11 commented Aug 10, 2022

I've fixed this locally but can't push up a branch.

I've changed the check from

if (!string.IsNullOrEmpty(objectName) && method != HttpMethod.Put) region = await GetRegion(bucketName).ConfigureAwait(false);

to

if ( method != HttpMethod.Put) region = await GetRegion(bucketName).ConfigureAwait(false);

and the code works as expected, could a pull request please be raised for it?

@ebozduman
Copy link
Collaborator

Fixed by PR #677

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants