5

The Minio JAVA SDK documentation doesn't clearly articulate how to create a folder inside a bucket.

Can somebody help me on this request ?

Thanks in Advance!

Rakshith Venkatesh
  • 481
  • 2
  • 5
  • 11

3 Answers3

9

In the objectName parameter prefix of the putObject method, you can specify a folder name. https://docs.minio.io/docs/java-client-api-reference#putObject https://github.com/minio/minio/issues/2423#issuecomment-239408168

For example:

//objectName = folderName + "/" + fileName;
minioClient.putObject(bucketName, objectName, inputStream, contentType);
Daniel Sobrado
  • 717
  • 1
  • 9
  • 22
Maxim Shatunov
  • 301
  • 1
  • 9
1

Create the bucket if its not present. To add folder within it add it to the name of file. Eg. File name: "sample.txt", Bucket Name: "main", SubFolder: "resrc" filePath: file which you want to upload

minioClient.putObject("main", "resrc" + "/" + "sample.txt", filePath);

Rumi singh
  • 21
  • 2
1

Create or check for exist.

// Create object ends with '/' (also called as folder or directory).
minioClient.putObject(
PutObjectArgs.builder().bucket("my-bucketname").object("path/to/").stream(
new ByteArrayInputStream(new byte[] {}), 0, -1).build());
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 31 '22 at 05:35