import (
"fmt"
"github.com/gin-gonic/gin"
"log"
"net/http"
)
func main(){
e := gin.Default()
//set a lower memory limit for multipart forms (default is 32 Mib)
e.MaxMultipartMemory = 8 << 20 //8Mib
e.POST("/upload", func(c *gin.Context) {
file,err := c.FormFile("file")
if err != nil {
c.JSON(http.StatusInternalServerError,gin.H{
"mssage":err.Error(),
})
}
log.Println(file.Filename) //print filename
dst := fmt.Sprintf("./%s",file.Filename) //构建目标文件的位置
//save the file to specific dst
c.SaveUploadedFile(file,dst)
c.JSON(http.StatusOK,gin.H{
"message":fmt.Sprintf("%s uploaded!",file.Filename),
})
})
e.Run(":9090")
}

991

被折叠的 条评论
为什么被折叠?



