1
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 !

Nick Farsi
  • 366
  • 4
  • 19

1 Answers1

2

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.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • Thanks, that worked! Could you by chance tell me why it gives me ```"There is an error in XML document (0, 0)."``` exception now? 'data' is an .xlsx workbook as byte[] created using ClosedXML. Did I specify content type wrong? – Nick Farsi Sep 08 '22 at 15:14
  • Without a stack trace or context, no, I can't say anything about that. Seems like something tries to parse something as XML, which it isn't. – CodeCaster Sep 08 '22 at 15:16
  • this exception is raised by MinioClient when ```await _client.PutObjectAsync(args);``` is called. Am I only supposed to store XML in Minio and other file types are not supported? – Nick Farsi Sep 08 '22 at 15:20
  • That's a different question though. Perhaps update your question with the exact code and exception you have, or ask a new one. – CodeCaster Sep 08 '22 at 15:23