Uploading Files Post Request – GinGonic golang framework 14

Uploading Files Post Request – GinGonic golang framework 14

//[sourcecode lang=”go” autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ gutter=”true” highlight=”1-3,6,9″ htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false” title=”Source Code main.go”] // File Upload in GinGonic 🙂
package main
import (
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



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: