I'm having an error that is rather hard to debug when uploading large files to a server made using golang's default net/http package. The upload code looks like this:
uploadForm.onsubmit = () => {
const formData = new FormData(uploadForm);
const isPublic : boolean = (<HTMLInputElement>document.getElementById('public_switch')).checked;
formData.append('file', (<HTMLInputElement>document.getElementById('file')).files[0]);
formData.append('compression', (<HTMLInputElement>document.getElementById('compression')).value);
formData.append('public', String(isPublic));
const xhr = new XMLHttpRequest();
xhr.open("POST", "/upload/");
xhr.send(formData);
xhr.onreadystatechange = function() {
console.log(xhr.responseText);
}
}
I have a server written in golang which I start as follows:
var server = &http.Server{
Addr: ":" + Configuration.Port,
ReadTimeout: 300 * time.Second,
WriteTimeout: 300 * time.Second,
ReadHeaderTimeout: 300 * time.Second,
MaxHeaderBytes: 500000000}
http.HandleFunc("/upload/", uploadFile)
server.ListenAndServe()
Finally I accept the and parse the file using the following code
func uploadFile(w http.ResponseWriter, r *http.Request) {
//Parsing the upload arguments into the values we shall be working with
r.ParseMultipartForm(5000000000000000)
file, _, err := r.FormFile("file")
//etc
Now, the code itself fails at 'r.FormFile("file")' with the very descriptive error message: "multipart: NextPart: EOF"
Is there some sort of setting on file limit or timeouts which I might not be setting either in the go code or in javascript ? The file I'm trying to upload is ~1.7GB so clearly fits within the limits supported by http.
Any idea how I could debug this issue a bit better without having to delve into FormFile or capture the request itself ? The code works just fine with smaller files ( a few Mb's).