Home > Enterprise >  How to upload byte[] to Minio
How to upload byte[] to Minio

Time:09-09

public async Task Put(byte[] data)
{
    var args = new PutObjectArgs { };
    args.WithBucket("buckethead");
    args.WithObject(Guid.NewGuid.ToString());
    args.WithRequestBody(data);
    args.WithContentType("application/vnd.ms-excel");
    await _client.PutObjectAsync(args);
}

First of all I gotta say that Minio is very poorly documented.

Second - how do I send byte[]? Example above gives the following error:

One of FileName or ObjectStreamData must be set.

But FileName implies usage of physically stored file and ObjectStreamData - there is no such method in PutObjectArgs !

CodePudding user response:

The methods are fluent (though you don't need to use that), you're looking for WithStreamData(), and wrap your byte array in a MemoryStream:

new PutObjectArgs()
    .With...
    .WithStreamData(new MemoryStream(data))
    .With...

The WithRequestBody() you call now will serialize the passed object to XML.

  • Related