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:
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user