summaryrefslogtreecommitdiff
path: root/src/rhimportd
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-07-23 18:44:59 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-07-23 18:44:59 (GMT)
commit8f38ca5d38495097ed87b105022da37bfbedede4 (patch)
tree75a7b56f28060f28793b1f5791ad42db0423c7e7 /src/rhimportd
parentb72af8f994e28e06c5aa00ff3995b726b8c5ed55 (diff)
print size and sha256 hash of finished upload
Diffstat (limited to 'src/rhimportd')
-rw-r--r--src/rhimportd/uploadWeb.go11
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
}