Browse Source

add ETag to upload results and chunks

pull/747/head
Chris Lu 6 years ago
parent
commit
7d6b2a4740
  1. 2
      weed/command/filer_copy.go
  2. 1
      weed/filesys/dirty_page.go
  3. 11
      weed/operation/upload_content.go
  4. 1
      weed/server/common.go

2
weed/command/filer_copy.go

@ -201,6 +201,7 @@ func uploadFileAsOne(filerAddress, filerGrpcAddress string, urlFolder string, f
Offset: 0,
Size: uint64(uploadResult.Size),
Mtime: time.Now().UnixNano(),
ETag: uploadResult.ETag,
})
fmt.Printf("copied %s => http://%s%s%s\n", fileName, filerAddress, urlFolder, fileName)
@ -278,6 +279,7 @@ func uploadFileInChunks(filerAddress, filerGrpcAddress string, urlFolder string,
Offset: i * chunkSize,
Size: uint64(uploadResult.Size),
Mtime: time.Now().UnixNano(),
ETag: uploadResult.ETag,
})
fmt.Printf("uploaded %s-%d to %s [%d,%d)\n", fileName, i+1, targetUrl, i*chunkSize, i*chunkSize+int64(uploadResult.Size))
}

1
weed/filesys/dirty_page.go

@ -187,6 +187,7 @@ func (pages *ContinuousDirtyPages) saveToStorage(ctx context.Context, buf []byte
Offset: offset,
Size: uint64(len(buf)),
Mtime: time.Now().UnixNano(),
ETag: uploadResult.ETag,
}, nil
}

11
weed/operation/upload_content.go

@ -22,6 +22,7 @@ type UploadResult struct {
Name string `json:"name,omitempty"`
Size uint32 `json:"size,omitempty"`
Error string `json:"error,omitempty"`
ETag string `json:"error,omitempty"`
}
var (
@ -90,6 +91,7 @@ func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error
return nil, post_err
}
defer resp.Body.Close()
etag := getEtag(resp)
resp_body, ra_err := ioutil.ReadAll(resp.Body)
if ra_err != nil {
return nil, ra_err
@ -103,5 +105,14 @@ func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error
if ret.Error != "" {
return nil, errors.New(ret.Error)
}
ret.ETag = etag
return &ret, nil
}
func getEtag(r *http.Response) (etag string) {
etag = r.Header.Get("ETag")
if strings.HasPrefix(etag, "\"") && strings.HasSuffix(etag, "\"") {
etag = etag[1 : len(etag)-1]
}
return
}

1
weed/server/common.go

@ -123,6 +123,7 @@ func submitForClientHandler(w http.ResponseWriter, r *http.Request, masterUrl st
m["fid"] = assignResult.Fid
m["fileUrl"] = assignResult.PublicUrl + "/" + assignResult.Fid
m["size"] = uploadResult.Size
m["eTag"] = uploadResult.ETag
writeJsonQuiet(w, r, http.StatusCreated, m)
return
}

Loading…
Cancel
Save