From b559d28a38067b0a5b065be6f639c5f3429cfaa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Mon, 24 Jan 2022 19:03:20 +0100 Subject: [PATCH] Add url to upload response --- api/http.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/api/http.go b/api/http.go index 0485261..08b59c1 100644 --- a/api/http.go +++ b/api/http.go @@ -4,6 +4,7 @@ import ( "encoding/json" "io" "net/http" + "path" "strconv" "strings" "time" @@ -84,6 +85,7 @@ func (s *HTTPServer) HandlerAPIFilePost(w http.ResponseWriter, r *http.Request) return } s.Logger.Infow("Stored file.", "req_id", reqID, "id", f.ID, "remote_addr", r.RemoteAddr) + fileURL := path.Join(s.config.URL, "/api/file", f.ID) var resp = struct { Message string `json:"message"` ID string `json:"id"` @@ -91,7 +93,7 @@ func (s *HTTPServer) HandlerAPIFilePost(w http.ResponseWriter, r *http.Request) }{ Message: "OK", ID: f.ID, - URL: "TODO", + URL: fileURL, } w.WriteHeader(http.StatusAccepted) encoder := json.NewEncoder(w) @@ -164,7 +166,8 @@ func (s *HTTPServer) processMultiPartFormUpload(w http.ResponseWriter, r *http.R } s.Logger.Infow("Stored file.", "req_id", reqID, "id", f.ID, "filename", f.OriginalFilename, "remote_addr", r.RemoteAddr) - responses = append(responses, ResponseAPIFilePost{Message: "OK", ID: f.ID, URL: "TODO"}) + fileURL := path.Join(s.config.URL, "/api/file", f.ID) + responses = append(responses, ResponseAPIFilePost{Message: "OK", ID: f.ID, URL: fileURL}) }