commit cc42dc8c15c9bc9537f09648c2199294bc668deb
parent 63d622e14a6b1db8e7fb9fb47ee745355b297894
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Mon, 30 Jan 2023 16:55:15 -0800
http post multipart body
Diffstat:
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/cmd/dkfupload/main.go b/cmd/dkfupload/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "bytes"
"context"
"encoding/hex"
"flag"
@@ -10,6 +11,7 @@ import (
"log"
"math"
"math/rand"
+ "mime/multipart"
"net"
"net/http"
"net/http/cookiejar"
@@ -100,7 +102,14 @@ func main() {
if !dry {
// TODO: http post the chunk to server
hasToSucceed(func() error {
- req, _ := http.NewRequest(http.MethodPost, baseUrl+"/file-drop/"+filedropUUID, nil)
+ body := new(bytes.Buffer)
+ w := multipart.NewWriter(body)
+ partFileName := fmt.Sprintf("part_%d", chunkNum)
+ part, _ := w.CreateFormFile("file", partFileName)
+ _, _ = part.Write(buf[:n])
+ _ = w.Close()
+
+ req, _ := http.NewRequest(http.MethodPost, baseUrl+"/file-drop/"+filedropUUID, body)
req.Header.Set("User-Agent", userAgent)
req.Header.Set("DKF_API_KEY", apiKey)
resp, err := client.Do(req)