feat(): add max file size for upload
This commit is contained in:
parent
ea6a7b272a
commit
48528f3a56
5
main.go
5
main.go
@ -14,6 +14,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
port = ":8080"
|
port = ":8080"
|
||||||
filesDir = "./files"
|
filesDir = "./files"
|
||||||
|
maxFileSize = 20 * 1024 * 1024 // 20MiB
|
||||||
)
|
)
|
||||||
|
|
||||||
var url string = os.Getenv("URL")
|
var url string = os.Getenv("URL")
|
||||||
@ -41,9 +42,11 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.Body = http.MaxBytesReader(w, r.Body, maxFileSize)
|
||||||
|
|
||||||
file, _, err := r.FormFile("file")
|
file, _, err := r.FormFile("file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Error retrieving the file", http.StatusBadRequest)
|
http.Error(w, "Error retrieving the file or file size exceeds limit", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
Loading…
Reference in New Issue
Block a user