Use MaxBytesReader to limit the size of the request. Before calling ParseMultiPartForm or FormFile, run the following line:
r.Body = http.MaxBytesReader(w, r.Body, max)
where r- *http.Request, and w- http.Response.
This limits the size of the entire request body, not a single file. If you upload one file at a time, the request body size limit should be a good approximation to the file size limit.
, r.ParseMultipartForm(maxMemory) r.FormFile(). maxMemory , .