volume: following md5 base64 encoding

fix https://github.com/chrislusf/seaweedfs/issues/1374
This commit is contained in:
Chris Lu 2020-06-28 07:25:50 -07:00
parent f0f884edd5
commit 20d9cfae86

View file

@ -2,6 +2,7 @@ package needle
import ( import (
"crypto/md5" "crypto/md5"
"encoding/base64"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -85,7 +86,7 @@ func ParseUpload(r *http.Request, sizeLimit int64) (pu *ParsedUpload, e error) {
if expectedChecksum := r.Header.Get("Content-MD5"); expectedChecksum != "" { if expectedChecksum := r.Header.Get("Content-MD5"); expectedChecksum != "" {
h := md5.New() h := md5.New()
h.Write(pu.UncompressedData) h.Write(pu.UncompressedData)
if receivedChecksum := fmt.Sprintf("%x", h.Sum(nil)); expectedChecksum != receivedChecksum { if receivedChecksum := base64.StdEncoding.EncodeToString(h.Sum(nil)); expectedChecksum != receivedChecksum {
e = fmt.Errorf("Content-MD5 did not match md5 of file data [%s] != [%s]", expectedChecksum, receivedChecksum) e = fmt.Errorf("Content-MD5 did not match md5 of file data [%s] != [%s]", expectedChecksum, receivedChecksum)
return return
} }