How to create empty folder/object in Minio using C#

43 Views Asked by At

I am using MinIO Client

I am doing a pet-project for cloud storage. I want to create a new empty folder in an existing bucket. How do i do this?

I have already tried doing it this way:

    public async Task CreateFolderAsync(string path, string folderName)
    {
        var args = new PutObjectArgs()
            .WithBucket(_configuration["MinIO:Bucket"])
            .WithObject(path + folderName + "/")
            .WithStreamData(new MemoryStream(new byte[] { }))
            .WithObjectSize(0);

        await _minioClient.PutObjectAsync(args).ConfigureAwait(false);
    }

but this code returns an error - System.InvalidOperationException: ObjectSize must be set

I haven't found any implementation of this one in c#, but I noticed that similar code works in java:

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

There are 0 best solutions below