fix(upload): clear error and higher limit for large files

- raise upload limit to 100 MB
- return 413 file_too_large on MaxBytesError instead of misleading
  "expected multipart form"
- client-side per-file and total size pre-check with a clear message
This commit is contained in:
iu
2026-10-10 19:15:43 +03:00
parent 3886cc6511
commit b02b165b3d
2 changed files with 20 additions and 2 deletions
+8 -2
View File
@@ -1,6 +1,7 @@
package photos
import (
"errors"
"io"
"net/http"
"strconv"
@@ -12,7 +13,7 @@ import (
"shared-album/internal/httpx"
)
const maxUploadSize = 50 << 20
const maxUploadSize = 100 << 20
type Handler struct {
svc *Service
@@ -43,7 +44,12 @@ func (h *Handler) Upload(c *gin.Context) {
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, maxUploadSize)
form, err := c.MultipartForm()
if err != nil {
httpx.RespondError(c, httpx.BadRequest("invalid_request", "expected multipart form"))
var maxErr *http.MaxBytesError
if errors.As(err, &maxErr) {
httpx.RespondError(c, httpx.NewError(http.StatusRequestEntityTooLarge, "file_too_large", "files exceed the maximum upload size (100 MB)"))
return
}
httpx.RespondError(c, httpx.BadRequest("invalid_request", "invalid multipart form"))
return
}
files := form.File["files"]