diff --git a/cmd/handler-utils.go b/cmd/handler-utils.go index 591f826ce..491ba9963 100644 --- a/cmd/handler-utils.go +++ b/cmd/handler-utils.go @@ -17,8 +17,10 @@ package cmd import ( + "bytes" "context" "io" + "io/ioutil" "mime/multipart" "net" "net/http" @@ -235,6 +237,19 @@ func extractPostPolicyFormValues(ctx context.Context, form *multipart.Form) (fil return nil, "", 0, nil, err } + // this means that filename="" was not specified for file key and Go has + // an ugly way of handling this situation. Refer here + // https://golang.org/src/mime/multipart/formdata.go#L61 + if len(form.File) == 0 { + var b = &bytes.Buffer{} + for _, v := range formValues["File"] { + b.WriteString(v) + } + fileSize = int64(b.Len()) + filePart = ioutil.NopCloser(b) + return filePart, fileName, fileSize, formValues, nil + } + // Iterator until we find a valid File field and break for k, v := range form.File { canonicalFormName := http.CanonicalHeaderKey(k) @@ -269,7 +284,6 @@ func extractPostPolicyFormValues(ctx context.Context, form *multipart.Form) (fil break } } - return filePart, fileName, fileSize, formValues, nil }