10

I want to add metadata to Minio object while adding the file as object to Minio object storage using python. I am able to find accessing metadata of object stored on Minio. but there is no example of adding metadata while adding file to Minio storage.

Regards, Ritu Ranjan

Rituranjan Routray
  • 109
  • 1
  • 1
  • 6

3 Answers3

8

Well it there is a examples at python minio client test

content_type='application/octet-stream'
metadata = {'x-amz-meta-testing': 'value'}
client.put_object(bucket_name,
                  object_name+'-metadata',
                  MB_11_reader,
                  MB_11,
                  content_type,
                  metadata)

The trick is that metadata dict should have keys in format 'x-amz-meta-youkey'

Ivan
  • 1,103
  • 2
  • 10
  • 15
1

You can use pyminio:

from pyminio import Pyminio

pyminio_client = Pyminio.from_credentials(
    endpoint='<your-minio-endpoint>',  # e.g. "localhost:9000/"
    access_key='<your-minio-access-key>',
    secret_key='<your-minio-secret-key>'
)

metadata = {'Pyminio-is': 'Awesome'}
pyminio_client.put_file(to_path='/foo/bar/baz', file_path='/mnt/some_file', metadata=metadata)

Its automaticly strips off the'x-amz-meta-' from the name of the variables so its more easy to use with pyminio_client.get('/foo/bar/baz')

1

You could check out the new documentation to compose objects, that is, combine objects and include metadata. https://min.io/docs/minio/linux/developers/python/API.html#compose_object

from minio.commonconfig import ComposeSource
from minio.sse import SseS3

sources = [
    ComposeSource("my-job-bucket", "my-object")
]

# Create my-bucket/my-object with user metadata by combining
# source object list.
result = client.compose_object(
    "my-bucket",
    "my-object",
    sources,
    metadata={"test_meta_key": "test_meta_value"},
)
print(result.object_name, result.version_id)