I have a simple upload form as
<html>
<title>Go upload</title>
<body>
<form action="http://localhost:8899/up" method="post" enctype="multipart/form-data">
<label for="file">File Path:</label>
<input type="text" name="filepath" id="filepath">
<p>
<label for="file">Content:</label>
<textarea name="jscontent" id="jscontent" style="width:500px;height:100px" rows="10" cols="80"></textarea>
<p>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
And server side
package main
import (
"net/http"
"log"
)
func defaultHandler(w http.ResponseWriter, r *http.Request) {
log.Println(r.PostFormValue("filepath"))
}
func main() {
http.HandleFunc("/up", defaultHandler)
http.ListenAndServe(":8899", nil)
}
The problem is when I use enctype="multipart/form-data"
, I cannot get the value from client with r.PostFormValue
, but it's ok if I set to enctype="application/x-www-form-urlencoded"
, go document say
PostFormValue returns the first value for the named component of the POST or PUT request body. URL query parameters are ignored. PostFormValue calls ParseMultipartForm and ParseForm if necessary and ignores any errors returned by these functions.
So why they did not say anything about enctype
here ?