Skip to content

ListObjects doesn't decode UserMetadata correctly #2054

Open
@Lumaraf

Description

@Lumaraf

When ListObjects is used with the WithMetadata: true option the returned UserMetadata is not decoded to what was set via PutObject and what GetObject and StatObject would return.

package main

import (
	"bytes"
	"context"
	"fmt"
	"github.com/minio/minio-go/v7"
	"github.com/minio/minio-go/v7/pkg/credentials"
)

func main() {
	client, err := minio.New("127.0.0.1:9000", &minio.Options{
		Creds:  credentials.NewStaticV4("minio-user", "minio-password", ""),
		Secure: false,
	})
	if err != nil {
		panic(err)
	}

	bucket := "usermeta-test"

	client.MakeBucket(context.Background(), bucket, minio.MakeBucketOptions{})
	defer func() {
		client.RemoveBucket(context.Background(), bucket)
	}()

	content := []byte("hello world")

	_, err = client.PutObject(context.Background(), bucket, "hello.txt", bytes.NewReader(content), int64(len(content)), minio.PutObjectOptions{
		UserMetadata: map[string]string{
			"Hello": "World",
		},
	})
	if err != nil {
		panic(err)
	}

	info, err := client.StatObject(context.Background(), bucket, "hello.txt", minio.StatObjectOptions{})
	if err != nil {
		panic(err)
	}
	fmt.Println("StatObject >", info.Key, info.UserMetadata)

	objs := client.ListObjects(context.Background(), bucket, minio.ListObjectsOptions{
		WithMetadata: true,
	})
	for obj := range objs {
		fmt.Println("ListObjects >", obj.Key, obj.UserMetadata)
	}
}

Output:

StatObject > hello.txt map[Hello:World]
ListObjects > hello.txt map[X-Amz-Meta-Hello:World content-type:application/octet-stream expires:Mon, 01 Jan 0001 00:00:00 GMT]

For StatObject UserMetadata contains exactly the same entries that were saved via PutObject. The UserMetadata returned by ListObjects still has a X-Amz-Meta-prefix for the keys and an additional content-type and expires entries.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions