**前端代码如下**
```
<input type="text" value="hello gin" id="txt" name="txt" />
<input type="file" id="upload" name="upload" onchange="upFile()"/>
function upFile() {
var formData = new FormData
var file = document.getElementById("upload").files[0]
var text = document.getElementById("text").value
formData.append("upload",file)
formData.append("text",text)
$.ajax({
url:"/file",
type:"POST",
contentType:false,
processData: false,
data:formData,
success:function () {
alert("上传成功")
}
})
}
```
后端可以接收,相应200,但gin我用c.PostForm无法接受文件,值为空
```
router.POST("/file", func(c *gin.Context) {
file := c.PostForm("upload")
fmt.Println(file)
})
```
更多评论