Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create empty folder/object or new file in new folder (not upload) in Minio using Java Api

Tags:

java

minio

I am using Java API (https://docs.min.io/docs/java-client-api-reference.html) to use Minio Client.

I want to create a new folder and a new file (empty or sample text) in existing bucket. How do I do it? Please note that I do not want to upload any existing file from local.

I am aware of below command:

minioClient.putObject(bucketName,objectName, "/path/to/file/object.txt");

But unlike above, I do not have "/path/to/file/object.txt" i.e. I want to create the new file directly in minio.

I saw some example in Python SDK:

client.put_object(
"my-bucket", "my-object", io.BytesIO(b"hello"), 5,
)

I would be fine with above but I need it in Java API? What does putObject (in Java) expects for above example?

like image 227
Mihir Avatar asked Jun 21 '26 23:06

Mihir


1 Answers

If you want to create an empty directory with minio and java you can do as below:

minioClient.putObject(
            PutObjectArgs.builder()
                    .bucket(bucketName)
                    .object("dir1/dir2/dir3/")
                    .stream(new ByteArrayInputStream(new byte[]{}), 0, -1)
                    .build());

which creates an empty dir3, and be aware to end your given path with "/".

like image 89
Jafar Amini Avatar answered Jun 24 '26 12:06

Jafar Amini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!