diff --git a/cmd/api-headers.go b/cmd/api-headers.go index 6c723a86e..2d0e848f7 100644 --- a/cmd/api-headers.go +++ b/cmd/api-headers.go @@ -136,7 +136,7 @@ func setObjectHeaders(ctx context.Context, w http.ResponseWriter, objInfo Object // Set tag count if object has tags if len(objInfo.UserTags) > 0 { tags, _ := tags.ParseObjectTags(objInfo.UserTags) - if tags.Count() > 0 { + if tags != nil && tags.Count() > 0 { w.Header()[xhttp.AmzTagCount] = []string{strconv.Itoa(tags.Count())} if opts.Tagging { // This is MinIO only extension to return back tags along with the count. diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index 6949dc724..bb7200212 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -72,6 +72,8 @@ const ( xMinIOErrCodeHeader = "x-minio-error-code" xMinIOErrDescHeader = "x-minio-error-desc" + + postPolicyBucketTagging = "tagging" ) // Check if there are buckets on server without corresponding entry in etcd backend and @@ -1415,6 +1417,19 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h return } + if formValues.Get(postPolicyBucketTagging) != "" { + tags, err := tags.ParseObjectXML(strings.NewReader(formValues.Get(postPolicyBucketTagging))) + if err != nil { + writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL) + return + } + tagsStr := tags.String() + opts.UserDefined[xhttp.AmzObjectTagging] = tagsStr + } else { + // avoid user set an invalid tag using `X-Amz-Tagging` + delete(opts.UserDefined, xhttp.AmzObjectTagging) + } + objInfo, err := objectAPI.PutObject(ctx, bucket, object, pReader, opts) if err != nil { writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL)