mirror of
https://github.com/minio/minio.git
synced 2024-12-23 21:55:53 -05:00
Handle POST object upload without filename param (#6221)
POST mime/multipart upload style can have filename value optional which leads to implementation issues in Go releases in their standard mime/multipart library. When `filename` doesn't exist Go doesn't update `form.File` which we rely on to extract the incoming file data, strangely when `filename` is not specified this data is buffered in memory and is now part of `form.Value` instead of `form.File` which creates an inconsistent behavior. This PR tries to fix this in our code for the time being, but ideal PR would be to fix the upstream mime/multipart library to handle the above situation consistently.
This commit is contained in:
parent
76c423392a
commit
e17e09ea3c
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user