From 321aefa026c00f36b299919baf32780a581e362b Mon Sep 17 00:00:00 2001 From: Rajiv Makhijani Date: Wed, 4 May 2016 15:24:10 -0700 Subject: [PATCH] Add Response for PostPolicyBucketHandler (#1477) (#1483) --- api-response.go | 15 +++++++++++++++ bucket-handlers.go | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/api-response.go b/api-response.go index 0fc424387..820680df7 100644 --- a/api-response.go +++ b/api-response.go @@ -194,6 +194,16 @@ type CompleteMultipartUploadResponse struct { ETag string } +// PostResponse container for completed post upload response +type PostResponse struct { + XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ PostResponse" json:"-"` + + Location string + Bucket string + Key string + ETag string +} + // DeleteError structure. type DeleteError struct { Code string @@ -217,6 +227,11 @@ func getLocation(r *http.Request) string { return r.URL.Path } +// getObjectLocation gets the relative URL for an object +func getObjectLocation(bucketName string, key string) string { + return "/" + bucketName + "/" + key +} + // takes an array of Bucketmetadata information for serialization // input: // array of bucket metadata diff --git a/bucket-handlers.go b/bucket-handlers.go index 6d4abfba2..e1f9e04a4 100644 --- a/bucket-handlers.go +++ b/bucket-handlers.go @@ -592,7 +592,14 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h if md5Sum != "" { w.Header().Set("ETag", "\""+md5Sum+"\"") } - writeSuccessResponse(w, nil) + encodedSuccessResponse := encodeResponse(PostResponse{ + Location: getObjectLocation(bucket, object), // TODO Full URL is preferred + Bucket: bucket, + Key: object, + ETag: md5Sum, + }) + setCommonHeaders(w) + writeSuccessResponse(w, encodedSuccessResponse) } // HeadBucketHandler - HEAD Bucket