'How to create empty folder/object or new file in new folder (not upload) in Minio using Java Api
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?
Solution 1:[1]
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 "/"
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |