browser: Object upload should save metadata and notify. (#2309)

Object upload from browser should save additional
incoming metadata. Additionally should also notify
through bucket notifications once they are set.

Fixes #2292
This commit is contained in:
Harshavardhana
2016-07-27 21:11:15 -07:00
committed by Anand Babu (AB) Periasamy
parent ad19bf0ec1
commit 65f71ce0c5
4 changed files with 36 additions and 10 deletions
+28 -2
View File
@@ -374,10 +374,36 @@ func (web *webAPIHandlers) Upload(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
bucket := vars["bucket"]
object := vars["object"]
// FIXME: Allow file upload handler to set content-type, content-encoding.
if _, err := web.ObjectAPI.PutObject(bucket, object, -1, r.Body, nil); err != nil {
// Extract incoming metadata if any.
metadata := extractMetadataFromHeader(r.Header)
if _, err := web.ObjectAPI.PutObject(bucket, object, -1, r.Body, metadata); err != nil {
writeWebErrorResponse(w, err)
return
}
// Load notification config if any.
nConfig, err := loadNotificationConfig(web.ObjectAPI, bucket)
// Notifications not set, return.
if err == errNoSuchNotifications {
return
}
// For all other errors, return.
if err != nil {
errorIf(err, "Unable to load notification config for bucket: \"%s\"", bucket)
return
}
// Fetch object info for notifications.
objInfo, err := web.ObjectAPI.GetObjectInfo(bucket, object)
if err != nil {
errorIf(err, "Unable to fetch object info for \"%s\"", path.Join(bucket, object))
return
}
// Notify object created event.
notifyObjectCreatedEvent(nConfig, ObjectCreatedPut, bucket, objInfo)
}
// Download - file download handler.