[#131] Add meta to PutObject
Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
parent
e7bebcc1aa
commit
e8bf46a2fa
2 changed files with 16 additions and 0 deletions
|
@ -47,11 +47,14 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metadata := parseMetadata(r)
|
||||||
|
|
||||||
params := &layer.PutObjectParams{
|
params := &layer.PutObjectParams{
|
||||||
Bucket: bkt,
|
Bucket: bkt,
|
||||||
Object: obj,
|
Object: obj,
|
||||||
Reader: r.Body,
|
Reader: r.Body,
|
||||||
Size: r.ContentLength,
|
Size: r.ContentLength,
|
||||||
|
Header: metadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
if info, err = h.obj.PutObject(r.Context(), params); err != nil {
|
if info, err = h.obj.PutObject(r.Context(), params); err != nil {
|
||||||
|
@ -74,6 +77,17 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
api.WriteSuccessResponseHeadersOnly(w)
|
api.WriteSuccessResponseHeadersOnly(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseMetadata(r *http.Request) map[string]string {
|
||||||
|
res := make(map[string]string)
|
||||||
|
for k, v := range r.Header {
|
||||||
|
if strings.HasPrefix(k, api.MetadataPrefix) {
|
||||||
|
key := strings.TrimPrefix(k, api.MetadataPrefix)
|
||||||
|
res[key] = v[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
func (h *handler) CreateBucketHandler(w http.ResponseWriter, r *http.Request) {
|
func (h *handler) CreateBucketHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
|
|
@ -2,6 +2,8 @@ package api
|
||||||
|
|
||||||
// Standard S3 HTTP request/response constants.
|
// Standard S3 HTTP request/response constants.
|
||||||
const (
|
const (
|
||||||
|
MetadataPrefix = "X-Amz-Meta-"
|
||||||
|
|
||||||
LastModified = "Last-Modified"
|
LastModified = "Last-Modified"
|
||||||
Date = "Date"
|
Date = "Date"
|
||||||
ETag = "ETag"
|
ETag = "ETag"
|
||||||
|
|
Loading…
Reference in a new issue