From cc2af0e449d1d736a75010b83fd5242e3e61a9d8 Mon Sep 17 00:00:00 2001 From: boojack Date: Thu, 16 Dec 2021 20:43:12 +0800 Subject: [PATCH] chore: update resource max size --- api/e/codes.go | 1 + api/resource.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/api/e/codes.go b/api/e/codes.go index b4324196..a0ff6985 100644 --- a/api/e/codes.go +++ b/api/e/codes.go @@ -5,6 +5,7 @@ var Codes = map[string]int{ "REQUEST_BODY_ERROR": 40001, "UPLOAD_FILE_ERROR": 40002, + "OVERLOAD_MAX_SIZE": 40003, "NOT_FOUND": 40400, "USER_NOT_FOUND": 40401, "RESOURCE_NOT_FOUND": 40402, diff --git a/api/resource.go b/api/resource.go index a5ad216f..3098e140 100644 --- a/api/resource.go +++ b/api/resource.go @@ -31,7 +31,12 @@ func handleGetMyResources(w http.ResponseWriter, r *http.Request) { func handleUploadResource(w http.ResponseWriter, r *http.Request) { userId, _ := GetUserIdInSession(r) - r.ParseMultipartForm(10 << 20) + err := r.ParseMultipartForm(5 << 20) + + if err != nil { + e.ErrorHandler(w, "OVERLOAD_MAX_SIZE", "The max size of resource is 5Mb.") + return + } file, handler, err := r.FormFile("file")