go web gin 上传文件
2021-02-28 23:28
阅读:570
YPE html>
标签:default charset package ade log BMI serve err nic
main.go
package main import ( "github.com/gin-gonic/gin" "net/http" "path" ) func main() { r :=gin.Default() r.LoadHTMLFiles("./upload.html") r.GET("/upload", func(c *gin.Context) { c.HTML(http.StatusOK,"upload.html",nil ) }) r.POST("/upload", func(c *gin.Context) { file,err :=c.FormFile("f1") if err != nil{ c.JSON(http.StatusInternalServerError,gin.H{ "message":err.Error(), }) } else { dst := path.Join("./"+file.Filename) c.SaveUploadedFile(file,dst) c.JSON(http.StatusOK,gin.H{ "message":"ok", "name":file.Filename, }) } //log.Printf(file.Filename) }) r.Run(":9999") /* 报错信息 { "message": "request Content-Type isn‘t multipart/form-data" } */ }
upload.html
Title
{{/*
不要忘记 请求文件类型*/}}
go web gin 上传文件
标签:default charset package ade log BMI serve err nic
原文地址:https://www.cnblogs.com/zexin88/p/14450121.html
评论
亲,登录后才可以留言!