Presigend Post: Error out when File is not found (#3723)

Follow S3 behavior when no File is sent in the presigned
post request form.
master
Anis Elleuch 8 years ago committed by Harshavardhana
parent 6800902b43
commit c9b1468c3b
  1. 6
      cmd/api-errors.go
  2. 6
      cmd/bucket-handlers.go
  3. 11
      cmd/handler-utils.go

@ -83,6 +83,7 @@ const (
ErrInvalidPartOrder ErrInvalidPartOrder
ErrAuthorizationHeaderMalformed ErrAuthorizationHeaderMalformed
ErrMalformedPOSTRequest ErrMalformedPOSTRequest
ErrPOSTFileRequired
ErrSignatureVersionNotSupported ErrSignatureVersionNotSupported
ErrBucketNotEmpty ErrBucketNotEmpty
ErrAllAccessDisabled ErrAllAccessDisabled
@ -333,6 +334,11 @@ var errorCodeResponse = map[APIErrorCode]APIError{
Description: "The body of your POST request is not well-formed multipart/form-data.", Description: "The body of your POST request is not well-formed multipart/form-data.",
HTTPStatusCode: http.StatusBadRequest, HTTPStatusCode: http.StatusBadRequest,
}, },
ErrPOSTFileRequired: {
Code: "InvalidArgument",
Description: "POST requires exactly one file upload per request.",
HTTPStatusCode: http.StatusBadRequest,
},
ErrSignatureVersionNotSupported: { ErrSignatureVersionNotSupported: {
Code: "InvalidRequest", Code: "InvalidRequest",
Description: "The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.", 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 return
} }
// Check if file is provided, error out otherwise.
if fileBody == nil {
writeErrorResponse(w, ErrPOSTFileRequired, r.URL)
return
}
// Close multipart file // Close multipart file
defer fileBody.Close() defer fileBody.Close()

@ -167,7 +167,7 @@ func extractPostPolicyFormValues(form *multipart.Form) (filePart io.ReadCloser,
canonicalFormName := http.CanonicalHeaderKey(k) canonicalFormName := http.CanonicalHeaderKey(k)
// Check if value's field exceeds S3 limit // Check if value's field exceeds S3 limit
if int64(len(v[0])) > maxFormFieldSize { if int64(len(v[0])) > maxFormFieldSize {
return nil, "", 0, nil, errSizeUnexpected return nil, "", 0, nil, traceError(errSizeUnexpected)
} }
// Set the form value // Set the form value
formValues[canonicalFormName] = v[0] formValues[canonicalFormName] = v[0]
@ -178,7 +178,7 @@ func extractPostPolicyFormValues(form *multipart.Form) (filePart io.ReadCloser,
canonicalFormName := http.CanonicalHeaderKey(k) canonicalFormName := http.CanonicalHeaderKey(k)
if canonicalFormName == "File" { if canonicalFormName == "File" {
if len(v) == 0 { if len(v) == 0 {
return nil, "", 0, nil, errInvalidArgument return nil, "", 0, nil, traceError(errInvalidArgument)
} }
// Fetch fileHeader which has the uploaded file information // Fetch fileHeader which has the uploaded file information
fileHeader := v[0] fileHeader := v[0]
@ -186,15 +186,18 @@ func extractPostPolicyFormValues(form *multipart.Form) (filePart io.ReadCloser,
fileName = fileHeader.Filename fileName = fileHeader.Filename
// Open the uploaded part // Open the uploaded part
filePart, err = fileHeader.Open() filePart, err = fileHeader.Open()
if err != nil {
return nil, "", 0, nil, traceError(err)
}
// Compute file size // Compute file size
fileSize, err = filePart.(io.Seeker).Seek(0, 2) fileSize, err = filePart.(io.Seeker).Seek(0, 2)
if err != nil { if err != nil {
return nil, "", 0, nil, err return nil, "", 0, nil, traceError(err)
} }
// Reset Seek to the beginning // Reset Seek to the beginning
_, err = filePart.(io.Seeker).Seek(0, 0) _, err = filePart.(io.Seeker).Seek(0, 0)
if err != nil { if err != nil {
return nil, "", 0, nil, err return nil, "", 0, nil, traceError(err)
} }
// File found and ready for reading // File found and ready for reading
break break

Loading…
Cancel
Save