@ -19,7 +19,6 @@ package cmd
import (
import (
"encoding/base64"
"encoding/base64"
"encoding/xml"
"encoding/xml"
"fmt"
"io"
"io"
"net/http"
"net/http"
"net/url"
"net/url"
@ -327,9 +326,7 @@ func (api objectAPIHandlers) DeleteMultipleObjectsHandler(w http.ResponseWriter,
ObjInfo : ObjectInfo {
ObjInfo : ObjectInfo {
Name : dobj . ObjectName ,
Name : dobj . ObjectName ,
} ,
} ,
ReqParams : map [ string ] string {
ReqParams : extractReqParams ( r ) ,
"sourceIPAddress" : r . RemoteAddr ,
} ,
} )
} )
}
}
}
}
@ -439,14 +436,25 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h
defer fileBody . Close ( )
defer fileBody . Close ( )
bucket := mux . Vars ( r ) [ "bucket" ]
bucket := mux . Vars ( r ) [ "bucket" ]
formValues [ "Bucket" ] = bucket
formValues . Set ( "Bucket" , bucket )
if fileName != "" && strings . Contains ( formValues [ "Key" ] , "${filename}" ) {
if fileName != "" && strings . Contains ( formValues . Get ( "Key" ) , "${filename}" ) {
// S3 feature to replace ${filename} found in Key form field
// S3 feature to replace ${filename} found in Key form field
// by the filename attribute passed in multipart
// by the filename attribute passed in multipart
formValues [ "Key" ] = strings . Replace ( formValues [ "Key" ] , "${filename}" , fileName , - 1 )
formValues . Set ( "Key" , strings . Replace ( formValues . Get ( "Key" ) , "${filename}" , fileName , - 1 ) )
}
object := formValues . Get ( "Key" )
successRedirect := formValues . Get ( "success_action_redirect" )
successStatus := formValues . Get ( "success_action_status" )
var redirectURL * url . URL
if successRedirect != "" {
redirectURL , err = url . Parse ( successRedirect )
if err != nil {
writeErrorResponse ( w , ErrMalformedPOSTRequest , r . URL )
return
}
}
}
object := formValues [ "Key" ]
// Verify policy signature.
// Verify policy signature.
apiErr := doesPolicySignatureMatch ( formValues )
apiErr := doesPolicySignatureMatch ( formValues )
@ -455,7 +463,7 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h
return
return
}
}
policyBytes , err := base64 . StdEncoding . DecodeString ( formValues [ "Policy" ] )
policyBytes , err := base64 . StdEncoding . DecodeString ( formValues . Get ( "Policy" ) )
if err != nil {
if err != nil {
writeErrorResponse ( w , ErrMalformedPOSTRequest , r . URL )
writeErrorResponse ( w , ErrMalformedPOSTRequest , r . URL )
return
return
@ -492,7 +500,6 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h
// Extract metadata to be saved from received Form.
// Extract metadata to be saved from received Form.
metadata := extractMetadataFromForm ( formValues )
metadata := extractMetadataFromForm ( formValues )
sha256sum := ""
sha256sum := ""
objectLock := globalNSMutex . NewNSLock ( bucket , object )
objectLock := globalNSMutex . NewNSLock ( bucket , object )
@ -505,31 +512,33 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h
writeErrorResponse ( w , toAPIErrorCode ( err ) , r . URL )
writeErrorResponse ( w , toAPIErrorCode ( err ) , r . URL )
return
return
}
}
w . Header ( ) . Set ( "ETag" , "\"" + objInfo . MD5Sum + "\"" )
w . Header ( ) . Set ( "ETag" , ` " ` + objInfo . MD5Sum + ` " ` )
w . Header ( ) . Set ( "Location" , getObjectLocation ( bucket , object ) )
w . Header ( ) . Set ( "Location" , getObjectLocation ( bucket , object ) )
successRedirect := formValues [ http . CanonicalHeaderKey ( "success_action_redirect" ) ]
// Notify object created event.
successStatus := formValues [ http . CanonicalHeaderKey ( "success_action_status" ) ]
defer eventNotify ( eventData {
Type : ObjectCreatedPost ,
Bucket : objInfo . Bucket ,
ObjInfo : objInfo ,
ReqParams : extractReqParams ( r ) ,
} )
if successStatus == "" && successRedirect == "" {
writeSuccessNoContent ( w )
} else {
if successRedirect != "" {
if successRedirect != "" {
redirectURL := successRedirect + "?" + fmt . Sprintf ( "bucket=%s&key=%s&etag=%s" ,
// Replace raw query params..
bucket ,
redirectURL . RawQuery = getRedirectPostRawQuery ( objInfo )
getURLEncodedName ( object ) ,
writeRedirectSeeOther ( w , redirectURL . String ( ) )
getURLEncodedName ( "\"" + objInfo . MD5Sum + "\"" ) )
return
}
writeRedirectSeeOther ( w , redirectURL )
} else {
// Decide what http response to send depending on success_action_status parameter
// Decide what http response to send depending on success_action_status parameter
switch successStatus {
switch successStatus {
case "201" :
case "201" :
resp := encodeResponse ( PostResponse {
resp := encodeResponse ( PostResponse {
Bucket : bucket ,
Bucket : o bjInfo . B ucket,
Key : object ,
Key : objInfo . Name ,
ETag : "\"" + objInfo . MD5Sum + "\"" ,
ETag : ` " ` + objInfo . MD5Sum + ` " ` ,
Location : getObjectLocation ( bucket , object ) ,
Location : getObjectLocation ( o bjInfo . B ucket, objInfo . Name ) ,
} )
} )
writeResponse ( w , http . StatusCreated , resp , "application/xml" )
writeResponse ( w , http . StatusCreated , resp , "application/xml" )
case "200" :
case "200" :
@ -538,18 +547,6 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h
writeSuccessNoContent ( w )
writeSuccessNoContent ( w )
}
}
}
}
}
// Notify object created event.
eventNotify ( eventData {
Type : ObjectCreatedPost ,
Bucket : bucket ,
ObjInfo : objInfo ,
ReqParams : map [ string ] string {
"sourceIPAddress" : r . RemoteAddr ,
} ,
} )
}
// HeadBucketHandler - HEAD Bucket
// HeadBucketHandler - HEAD Bucket
// ----------
// ----------