In Go, you can read a form sent using Ajax and FormData using r.ParseMultipartForm()
, which populates the Form
map with form request data.
func form(w http.ResponseWriter, r *http.Request) {
r.ParseMultipartForm(500) //
fmt.Fprintf(w, "This is the value of %+v", r.Form)
}
However, I haven't found a method to parse Blobs. The above code returns an empty map whenever instead of sending a form, I send a Blob. That is, when I send this:
var blob = new Blob([JSON.stringify(someJavascriptObj)]);
//XHR initialization, etc. etc.
xhr.send(blob);
the Go code above doesn't work. Now, when I send this:
var form = new FormData(document.querySelector("form"));
//...
xhr.send(form);
I can read form data without problems.