From 45f992da51c13cb257e001677cd68d71f048aa81 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Thu, 30 May 2019 20:53:13 +0300 Subject: [PATCH] Ability to leave comment to uploaded file --- README | 2 ++ src/uploader/main.go | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README b/README index 823492a..5d674a9 100644 --- a/README +++ b/README @@ -6,6 +6,8 @@ You can upload files with curl: curl -F fileupload=@somedata.tar.gpg http://localhost:8086/upload/ + curl -F fileupload=@somedata.tar.gpg -F comment="optional comment" http://localhost:8086/upload/ + You can verify integrity locally: b2sum -a blake2b somedata.tar.gpg diff --git a/src/uploader/main.go b/src/uploader/main.go index e2154cd..c3efd61 100644 --- a/src/uploader/main.go +++ b/src/uploader/main.go @@ -23,15 +23,19 @@ import ( ) const ( - WriteBufSize = 1 << 20 - FileFieldName = "fileupload" + WriteBufSize = 1 << 20 + FileFieldName = "fileupload" + CommentFieldName = "comment" ) var ( Index = template.Must(template.New("index").Parse(` Upload
- +
+ +
+
`)) ) @@ -88,6 +92,16 @@ func upload(w http.ResponseWriter, r *http.Request) { } fmt.Fprintf(w, "Timestamp: %s\nBytes: %d\nBLAKE2b: %s\n", fn, n, sum) log.Println(r.RemoteAddr, fn, p.FileName(), n, sum) + p, err = mr.NextPart() + if err != nil || p.FormName() != CommentFieldName { + return + } + comment, err := ioutil.ReadAll(p) + if err != nil || len(comment) == 0 { + return + } + ioutil.WriteFile(fn+".txt", comment, os.FileMode(0600)) + go notify(fn, n, string(comment)) } func main() { -- 2.44.0