diff options
-rw-r--r-- | src/rhimportd/uploadWeb.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/rhimportd/uploadWeb.go b/src/rhimportd/uploadWeb.go index 9d16e92..d60fb22 100644 --- a/src/rhimportd/uploadWeb.go +++ b/src/rhimportd/uploadWeb.go @@ -25,6 +25,8 @@ package main import ( + "crypto/sha256" + "encoding/hex" "encoding/json" "io" "net/http" @@ -89,12 +91,16 @@ func webUploadHandler(conf *rhimport.Config, db *rddb.DBChan, sessions *rhimport defer close(attachmentChan) rhl.Printf("WebUploadHandler: starting file upload for '%s/%s'", username, sessionid) + sizeTotal := uint64(0) + hash := sha256.New() + body := io.TeeReader(r.Body, hash) for { chunk := rhimport.AttachmentChunk{} var data [128 * 1024]byte - n, err := r.Body.Read(data[:]) + n, err := body.Read(data[:]) if n > 0 { + sizeTotal += uint64(n) chunk.Data = data[:n] if err == io.EOF { err = nil @@ -102,7 +108,8 @@ func webUploadHandler(conf *rhimport.Config, db *rddb.DBChan, sessions *rhimport } chunk.Error = err if err == io.EOF { - rhl.Printf("WebUploadHandler: file upload for '%s/%s' finished", username, sessionid) + hashStr := hex.EncodeToString(hash.Sum(nil)) + rhl.Printf("WebUploadHandler: file upload for '%s/%s' finished (%d bytes, SHA256: %s)", username, sessionid, sizeTotal, hashStr) webUploadSuccessResponse(w) return } |