mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
Presigend Post: Error out when File is not found (#3723)
Follow S3 behavior when no File is sent in the presigned post request form.
This commit is contained in:
parent
6800902b43
commit
c9b1468c3b
@ -83,6 +83,7 @@ const (
|
||||
ErrInvalidPartOrder
|
||||
ErrAuthorizationHeaderMalformed
|
||||
ErrMalformedPOSTRequest
|
||||
ErrPOSTFileRequired
|
||||
ErrSignatureVersionNotSupported
|
||||
ErrBucketNotEmpty
|
||||
ErrAllAccessDisabled
|
||||
@ -333,6 +334,11 @@ var errorCodeResponse = map[APIErrorCode]APIError{
|
||||
Description: "The body of your POST request is not well-formed multipart/form-data.",
|
||||
HTTPStatusCode: http.StatusBadRequest,
|
||||
},
|
||||
ErrPOSTFileRequired: {
|
||||
Code: "InvalidArgument",
|
||||
Description: "POST requires exactly one file upload per request.",
|
||||
HTTPStatusCode: http.StatusBadRequest,
|
||||
},
|
||||
ErrSignatureVersionNotSupported: {
|
||||
Code: "InvalidRequest",
|
||||
Description: "The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.",
|
||||
|
@ -428,6 +428,12 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h
|
||||
return
|
||||
}
|
||||
|
||||
// Check if file is provided, error out otherwise.
|
||||
if fileBody == nil {
|
||||
writeErrorResponse(w, ErrPOSTFileRequired, r.URL)
|
||||
return
|
||||
}
|
||||
|
||||
// Close multipart file
|
||||
defer fileBody.Close()
|
||||
|
||||
|
@ -167,7 +167,7 @@ func extractPostPolicyFormValues(form *multipart.Form) (filePart io.ReadCloser,
|
||||
canonicalFormName := http.CanonicalHeaderKey(k)
|
||||
// Check if value's field exceeds S3 limit
|
||||
if int64(len(v[0])) > maxFormFieldSize {
|
||||
return nil, "", 0, nil, errSizeUnexpected
|
||||
return nil, "", 0, nil, traceError(errSizeUnexpected)
|
||||
}
|
||||
// Set the form value
|
||||
formValues[canonicalFormName] = v[0]
|
||||
@ -178,7 +178,7 @@ func extractPostPolicyFormValues(form *multipart.Form) (filePart io.ReadCloser,
|
||||
canonicalFormName := http.CanonicalHeaderKey(k)
|
||||
if canonicalFormName == "File" {
|
||||
if len(v) == 0 {
|
||||
return nil, "", 0, nil, errInvalidArgument
|
||||
return nil, "", 0, nil, traceError(errInvalidArgument)
|
||||
}
|
||||
// Fetch fileHeader which has the uploaded file information
|
||||
fileHeader := v[0]
|
||||
@ -186,15 +186,18 @@ func extractPostPolicyFormValues(form *multipart.Form) (filePart io.ReadCloser,
|
||||
fileName = fileHeader.Filename
|
||||
// Open the uploaded part
|
||||
filePart, err = fileHeader.Open()
|
||||
if err != nil {
|
||||
return nil, "", 0, nil, traceError(err)
|
||||
}
|
||||
// Compute file size
|
||||
fileSize, err = filePart.(io.Seeker).Seek(0, 2)
|
||||
if err != nil {
|
||||
return nil, "", 0, nil, err
|
||||
return nil, "", 0, nil, traceError(err)
|
||||
}
|
||||
// Reset Seek to the beginning
|
||||
_, err = filePart.(io.Seeker).Seek(0, 0)
|
||||
if err != nil {
|
||||
return nil, "", 0, nil, err
|
||||
return nil, "", 0, nil, traceError(err)
|
||||
}
|
||||
// File found and ready for reading
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user