Skip to content

Annotations and ZIP

Attach annotations to objects and extract ZIP archives on upload.
Note

Object annotations (?annotation) and ZIP member extraction (x-minio-extract) are Preview features in the MVP scope. Annotations also depend on four silo-pkg policy actions (s3:*ObjectAnnotation*) that have not been published to the public silo-pkg repository yet, and the general Silo Console (2.6.0) does not include an annotation UI.

This tutorial uses SigV4-signed Python requests to write, read, list and delete object annotations, and to list and read members inside an uploaded ZIP archive without unpacking it into separate S3 objects. Complete Use an S3 SDK first.

Interfaces and permissions

An annotation is attached to a specific parent object version. Each annotation body must be valid UTF-8 text between 1 byte and 1 MiB, and each parent version accepts at most 1,000 annotation names. Updating or deleting an annotation leaves the parent object’s body, ETag and Last-Modified timestamp unchanged.

OperationSigV4-signed HTTP requestRequired IAM action
Create or replacePUT /attachments/<key>?annotation=&annotationName=labels.jsons3:PutObjectAnnotation
Read bodyGET /attachments/<key>?annotation=&annotationName=labels.jsons3:GetObjectAnnotation
List namesGET /attachments/<key>?annotation=s3:ListObjectAnnotations
DeleteDELETE /attachments/<key>?annotation=&annotationName=labels.jsons3:DeleteObjectAnnotation

Standard object actions (s3:GetObject, s3:PutObject) do not grant annotation access. Pass versionId in the query string to target a historical version, or x-amz-object-if-match on PUT/DELETE to require a matching parent ETag. Annotation bodies inherit the parent object’s server-side encryption mode.

To read or list members inside a ZIP archive stored as an S3 object, include header x-minio-extract: true:

  • Read or stat a member: GET or HEAD /attachments/demo.zip/readme.txt with x-minio-extract: true.
  • List archive members: GET /attachments?list-type=2&prefix=demo.zip/ with x-minio-extract: true.

ZIP extraction reads directly from the parent object snapshot without persisting member objects or an index table. It supports Store and Deflate compression (plus bounded ZIP64), up to 10,000 central-directory entries, and up to 256 MiB per uncompressed member. Range and partNumber requests on ZIP members are not supported.

Complete Python example

Because standard S3 SDKs do not have built-in methods for ?annotation or x-minio-extract, sign the requests with botocore.auth.SigV4Auth. Save the script below as ~/.local/share/silo-tutorial/extensions.py:

import hashlib
import io
import json
import os
import ssl
import urllib.request
import zipfile
from urllib.parse import quote, urlencode

import boto3
from botocore.auth import SigV4Auth
from botocore.awsrequest import AWSRequest
from botocore.config import Config

endpoint = os.environ["SILO_ENDPOINT"].rstrip("/")
ca = os.environ["AWS_CA_BUNDLE"]
region = "us-east-1"
session = boto3.Session(profile_name="silo-admin", region_name=region)
credentials = session.get_credentials().get_frozen_credentials()
context = ssl.create_default_context(cafile=ca)

def signed_request(method, key, query=None, body=None, headers=None):
    url = endpoint + "/attachments/" + quote(key, safe="/")
    if query is not None:
        url += "?" + urlencode(query)
    request_headers = dict(headers or {})
    request_headers["x-amz-content-sha256"] = hashlib.sha256(body or b"").hexdigest()
    signed = AWSRequest(method=method, url=url, data=body, headers=request_headers)
    SigV4Auth(credentials, "s3", region).add_auth(signed)
    prepared = signed.prepare()
    request = urllib.request.Request(
        prepared.url, data=body, headers=dict(prepared.headers), method=method
    )
    with urllib.request.urlopen(request, context=context, timeout=60) as response:
        return response.status, response.read()

s3 = session.client(
    "s3",
    endpoint_url=endpoint,
    verify=ca,
    config=Config(signature_version="s3v4", s3={"addressing_style": "path"}),
)
parent = "extensions/invoice.txt"
s3.put_object(Bucket="attachments", Key=parent, Body=b"invoice 1001\n")
query = {"annotation": "", "annotationName": "labels.json"}
body = json.dumps({"invoice_id": 1001, "status": "paid"}).encode("utf-8")
print(signed_request("PUT", parent, query, body, {"Content-Type": "application/json"})[0])
print(signed_request("GET", parent, query)[1].decode("utf-8"))
print(signed_request("GET", parent, {"annotation": ""})[1].decode("utf-8"))
print(signed_request("DELETE", parent, query)[0])

archive = io.BytesIO()
with zipfile.ZipFile(archive, "w", compression=zipfile.ZIP_DEFLATED) as output:
    output.writestr("readme.txt", "hello from ZIP\n")
s3.put_object(Bucket="attachments", Key="demo.zip", Body=archive.getvalue())
print(signed_request("GET", "demo.zip/readme.txt", headers={"x-minio-extract": "true"})[1].decode("utf-8"))
print(signed_request("HEAD", "demo.zip/readme.txt", headers={"x-minio-extract": "true"})[0])
print(signed_request("GET", "", {"list-type": "2", "prefix": "demo.zip/"},
                     headers={"x-minio-extract": "true"})[1].decode("utf-8"))

Run the script:

"$HOME/.local/share/silo-tutorial/venv/bin/python" "$HOME/.local/share/silo-tutorial/extensions.py"

The script prints the PUT status (200), the annotation JSON, the annotation list XML, the DELETE status (204), the extracted hello from ZIP member content, the HEAD status (200), and the ListObjectsV2 XML for demo.zip/. See Annotations and ZIP extraction for full protocol rules and error codes.

Scan to open this page
https://mimus.pgsty.com/docs/s3/tutorial/annotations-zip/