Metadata on Minio object storage
Asked Answered
P

3

11

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.

Propeller answered 12/3, 2018 at 8:12 Comment(0)
T
9

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'

Tagmemics answered 24/4, 2018 at 13:34 Comment(0)
A
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')

Antitype answered 14/10, 2020 at 17:3 Comment(0)
C
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)
Cloudburst answered 27/2, 2023 at 5:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.