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.
r.ParseMultipartForm(500)
Perhaps an error is being returned here? Try capturing the error:
if err := r.ParseMultipartForm(500); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
Also, consider raising the 500 byte memory limit as larger blobs will be written to temporary files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With