Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minio Python Client: Upload Bytes directly

Tags:

python

minio

I read the minio docs and I see two methods to upload data:

  • put_object() this needs a io-stream
  • fput_object() this reads a file on disk

I want to test minio and upload some data I just created with numpy.random.bytes().

How to upload data which is stored in a variable in the python interpreter?

like image 382
guettli Avatar asked Jul 09 '26 08:07

guettli


1 Answers

Take a look at io.BytesIO. These allow you to wrap byte arrays up in a stream which you can give to minio.

For example:

import io
from minio import Minio

value = "Some text I want to upload"
value_as_bytes = value.encode('utf-8')
value_as_a_stream = io.BytesIO(value_as_bytes)

client = Minio("my-url-here", ...) # Edit this bit to connect to your Minio server
client.put_object("my_bucket", "my_key", value_as_a_stream , length=len(value_as_bytes))
like image 134
Alan Avatar answered Jul 12 '26 02:07

Alan