Uploading Files Post Request – GinGonic golang framework 14

Uploading Files Post Request – GinGonic golang framework 14

//

// File Upload in GinGonic 🙂
package main
import (
    "path/filepath"
    "github.com/gin-gonic/gin"
)
func main() {
    r := gin.Default()
    r.Static("/", "./public") // our static files dir/folder
    // post request == uploading files via post req
    r.POST("/upload", func(c *gin.Context) {
        file, _ := c.FormFile("file") // file is the name of html input name="file"
        filePath := filepath.Base(file.Filename) // we will get the base file name
        c.SaveUploadedFile(file, filePath)       // first arg is file itself
        // 2nd arg is the filepath+file name
        c.String(200, "file Uploaded...")
        // you can do someting like this also
        //c.Redirect(200, "/")
        // Lets create html file first and public folder also
    })
    r.Run()
}

TAGS#

gin gonic tutorial
gin-gonic / examples
gin-gonic documentation
gin framework tutorial
gin web framework
gin router
golang gin context
gin router group

###Buy Me a Coffee https://www.buymeacoffee.com/khan1

Tony BB
 

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: