Document Bearer-authenticated multipart uploads with curl and Wget2. Return 413 for oversized multipart bodies and report attachment size limits accurately.
This commit is contained in:
1 parent
12631ecd09
commit
61018a90b5
5 files changed
+149
-6
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/lgcosta/notas-online/internal/store"
|
||||
@@ -19,7 +20,12 @@ const maxUploadBody = store.MaxFileBytes + 64<<10
|
||||
func (s *Server) handleFileUpload(w http.ResponseWriter, r *http.Request) {
|
||||
r.Body = http.MaxBytesReader(w, r.Body, maxUploadBody)
|
||||
if err := r.ParseMultipartForm(8 << 20); err != nil {
|
||||
writeError(w, http.StatusBadRequest, "multipart inválido ou excede limite: "+err.Error())
|
||||
var maxErr *http.MaxBytesError
|
||||
if errors.As(err, &maxErr) {
|
||||
writeError(w, http.StatusRequestEntityTooLarge, "upload excede o limite de 64 MiB")
|
||||
} else {
|
||||
writeError(w, http.StatusBadRequest, "multipart inválido")
|
||||
}
|
||||
return
|
||||
}
|
||||
defer r.MultipartForm.RemoveAll()
|
||||
|
||||
Reference in new issue
Block a user