I've encountered a challenging error while uploading large files to a server built with Golang's default net/http package. The upload process is defined as follows:
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);
}
}
The server, written in Golang, is initiated like so:
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()
Upon receiving the file, it goes through the following processing 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
However, when reaching 'r.FormFile("file")' an error message stating "multipart: NextPart: EOF" is displayed.
Could there be specific settings for file limits or timeouts that I am missing in either the Go code or JavaScript? The file being uploaded is approximately 1.7GB and well within the supported HTTP limits.
Any suggestions on how I can improve debugging this issue without diving deep into FormFile or capturing the request itself? The code functions flawlessly with smaller files (only a few MB).