diff --git a/cmd/frontend/pdf.go b/cmd/frontend/pdf.go index 9ee59d6..5e4c399 100644 --- a/cmd/frontend/pdf.go +++ b/cmd/frontend/pdf.go @@ -5,6 +5,7 @@ import ( "log" "net/http" "path/filepath" + "strings" "github.com/google/uuid" b "streifling.com/jason/cpolis/cmd/backend" @@ -17,7 +18,7 @@ func UploadPDF(c *b.Config, s map[string]*Session) http.HandlerFunc { return } - file, _, err := r.FormFile("pdf-upload") + file, header, err := r.FormFile("pdf-upload") if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -43,7 +44,9 @@ func UploadPDF(c *b.Config, s map[string]*Session) http.HandlerFunc { return } - filename := fmt.Sprint(uuid.New(), ".pdf") + oldFilename := header.Filename + oldFilename = strings.Join(strings.Split(oldFilename, ".")[:len(oldFilename)-1], ".") + filename := fmt.Sprint(oldFilename, ".", uuid.New(), ".pdf") absFilepath, err := filepath.Abs(c.PDFDir + "/" + filename) if err != nil { log.Println(err)