-
Notifications
You must be signed in to change notification settings - Fork 693
Closed
Labels
Description
If I'm copying a file and transfer the UserMetadata
, the ContentType
is lost and defaults to binary/octet-stream
.
func TestCopyWithContentType(t *testing.T) {
client, err := minio.New("127.0.0.1:9000", &minio.Options{
Creds: credentials.NewStaticV4("minioadmin", "minioadmin", ""),
Secure: false,
})
if err != nil {
panic(err)
}
bucket := "unittest"
ctx := context.Background()
_ = client.MakeBucket(ctx, bucket, minio.MakeBucketOptions{})
content := []byte("some text")
if _, err := client.PutObject(ctx, bucket, "file1.txt", bytes.NewReader(content), int64(len(content)), minio.PutObjectOptions{ContentType: "text/plain"}); err != nil {
panic(err)
}
uploadedInfo, err := client.StatObject(ctx, bucket, "file1.txt", minio.StatObjectOptions{})
if err != nil {
panic(err)
}
// Replacing the Metadata is important to cause this issue
if _, err := client.CopyObject(ctx, minio.CopyDestOptions{Bucket: bucket, Object: "file2.txt", UserMetadata: uploadedInfo.UserMetadata, ReplaceMetadata: true}, minio.CopySrcOptions{Bucket: bucket, Object: "file1.txt"}); err != nil {
panic(err)
}
copiedInfo, err := client.StatObject(ctx, bucket, "file2.txt", minio.StatObjectOptions{})
if err != nil {
panic(err)
}
if uploadedInfo.ContentType != copiedInfo.ContentType { // text/plain != binary/octet-stream
t.FailNow()
}
}
I understand that's b/c minio handles this particular entry differently, e.g. client.PutObject(ctx, bucket, "file1.txt", bytes.NewReader(content), int64(len(content)), minio.PutObjectOptions{UserMetadata: map[string]string{"Content-Type": "text/plain"}})
will cause an error Content-Type unsupported user defined metadata name
, so I guess this "special handling" is missing when invoking Copy
.