2

I am trying to read files from S3 bucket using minio client.

https://docs.min.io/docs/java-client-quickstart-guide.html

I am able to make connection using this client and able to access the bucket also. Now, I need to access a file inside a folder in the bucket but I am not sure how to do it. I thought once I have access to the bucket, I can list out the file names using File library but not able to do it.

File path : s3 bucket endpoint/4275/input/test.csv

Code :

public void listS3BucketObject() {
        MinioClient minioClient =
                MinioClient.builder()
                        .endpoint(s3BucketEndpoint)
                        .credentials(s3BucketAccessKey, s3BucketSecretKey)
                        .build();

        String fileUrl = s3BucketEndpoint + "/" + "4275" + "/" + "input";
    
        File[] fileList =  new File(fileUrl).listFiles();
        for(File file : fileList) {
                      System.out.println("File name: "+file.getName()); // getting null exception here
Praveenks
  • 1,436
  • 9
  • 40
  • 79

1 Answers1

2

To list a "folder" (called a prefix in S3 terms), use the listObjects call.

See this for an example: https://docs.min.io/docs/java-client-api-reference.html#listObjects

sh0dan
  • 160
  • 8