blob: 4e528df96d4dfeca6612348f136f8dd936da2daf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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")
}
|