Browse Source

save s3 metadata to filer.

pull/1569/head
ruitao.liu 4 years ago
parent
commit
2dcc178d0a
  1. 2
      weed/server/filer_server_handlers_read.go
  2. 35
      weed/server/filer_server_handlers_write_autochunk.go

2
weed/server/filer_server_handlers_read.go

@ -97,7 +97,7 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request,
if r.Method == "GET" {
tagCount := 0
for k, _ := range entry.Extended {
if strings.HasPrefix(k, "x-amz-tagging-") {
if strings.HasPrefix(k, "X-Amz-Tagging-") {
tagCount++
}
}

35
weed/server/filer_server_handlers_write_autochunk.go

@ -176,6 +176,8 @@ func (fs *FilerServer) saveMetaData(ctx context.Context, r *http.Request, fileNa
Size: chunkOffset,
}
fs.saveAmzMetaData(r, entry)
if dbErr := fs.filer.CreateEntry(ctx, entry, false, false, nil); dbErr != nil {
fs.filer.DeleteChunks(entry.Chunks)
replyerr = dbErr
@ -308,3 +310,36 @@ func (fs *FilerServer) mkdir(ctx context.Context, w http.ResponseWriter, r *http
}
return filerResult, replyerr
}
func (fs *FilerServer) saveAmzMetaData(r *http.Request, entry *filer.Entry) {
var (
storageClass = "X-Amz-Storage-Class"
objectTagging = "X-Amz-Tagging"
userMetaPrefix = "X-Amz-Meta-"
)
if entry.Extended == nil {
entry.Extended = make(map[string][]byte)
}
if sc := r.Header.Get(storageClass); sc != "" {
entry.Extended[storageClass] = []byte(sc)
}
if tags := r.Header.Get(objectTagging); tags != "" {
for _, v := range strings.Split(tags, "&") {
tag := strings.Split(v, "=")
if len(tag) == 2 {
entry.Extended[objectTagging+"-"+tag[0]] = []byte(tag[1])
}
}
}
for header, values := range r.Header {
if strings.HasPrefix(header, userMetaPrefix) {
for _, value := range values {
entry.Extended[header] = []byte(value)
}
}
}
}
Loading…
Cancel
Save