From ad2f596828f6f66e5c06be64497fab56b085dff5 Mon Sep 17 00:00:00 2001 From: veradec Date: Wed, 11 Nov 2026 13:14:08 +0530 Subject: init: basic file uploading works --- main.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..4e528df --- /dev/null +++ b/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "net/http" + "fmt" + "path/filepath" + "github.com/gin-gonic/gin" +) + +func index(c *gin.Context){ + +} + +func main(){ + router := gin.Default() + + router.POST("/", func(c *gin.Context) { + // single file + file, err := c.FormFile("file") + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + fmt.Println(file.Filename) + + dst := filepath.Join("./files/", filepath.Base(file.Filename)) + c.SaveUploadedFile(file, dst) + c.String(http.StatusOK, fmt.Sprintf("'%s' uploaded!\n", file.Filename)) + }) + router.Run(":8080") +} -- cgit v1.2.3