From 8230c72ec68d1a928a9240802e8f752cc0ab3f6e Mon Sep 17 00:00:00 2001 From: John Date: Sun, 15 Mar 2020 20:11:38 +0800 Subject: [PATCH] improve file uploading feature for ghttp.Request --- net/ghttp/ghttp_request_param_file.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/ghttp/ghttp_request_param_file.go b/net/ghttp/ghttp_request_param_file.go index 65f3e8f81..b808d6cf1 100644 --- a/net/ghttp/ghttp_request_param_file.go +++ b/net/ghttp/ghttp_request_param_file.go @@ -36,7 +36,7 @@ type UploadFiles []*UploadFile // Note that it will overwrite the target file if there's already a same name file exist. func (f *UploadFile) Save(dirPath string, randomlyRename ...bool) (filename string, err error) { if f == nil { - return + return "", errors.New("file is empty, maybe you retrieve it from invalid field name or form enctype") } if !gfile.Exists(dirPath) { if err = gfile.Mkdir(dirPath); err != nil { @@ -77,7 +77,7 @@ func (f *UploadFile) Save(dirPath string, randomlyRename ...bool) (filename stri // The parameter specifies whether randomly renames all the file names. func (fs UploadFiles) Save(dirPath string, randomlyRename ...bool) (filenames []string, err error) { if len(fs) == 0 { - return nil, nil + return nil, errors.New("file array is empty, maybe you retrieve it from invalid field name or form enctype") } for _, f := range fs { if filename, err := f.Save(dirPath, randomlyRename...); err != nil {