Limit file upload size

This commit is contained in:
Bel LaPointe
2020-07-24 23:57:24 -06:00
parent c47850647e
commit 8741db40b4
2 changed files with 8 additions and 5 deletions

View File

@@ -77,8 +77,7 @@ func filesPostFromDirectLink(w http.ResponseWriter, r *http.Request) error {
return err
}
defer f.Close()
// TODO max bytes reader
_, err = io.Copy(f, resp.Body)
_, err = io.Copy(f, io.LimitReader(resp.Body, config.New().MaxFileSize))
return err
}
@@ -97,14 +96,15 @@ func filesPostFromUpload(w http.ResponseWriter, r *http.Request) error {
return err
}
defer f.Close()
megabyte := 100 << 20
r.ParseMultipartForm(int64(megabyte))
megabyte := 1 << 20
chunkSize := 10 * megabyte
r.ParseMultipartForm(int64(chunkSize))
file, _, err := r.FormFile("file")
if err != nil {
return err
}
defer file.Close()
if _, err := io.Copy(f, file); err != nil {
if _, err := io.Copy(f, io.LimitReader(file, config.New().MaxFileSize)); err != nil {
return err
}
return json.NewEncoder(w).Encode(map[string]interface{}{"status": "ok"})