fix:上传大图限制
This commit is contained in:
		
							parent
							
								
									f8c86b1f03
								
							
						
					
					
						commit
						05137f3fe5
					
				| @ -1,7 +1,7 @@ | |||||||
| Name: upload | Name: upload | ||||||
| Host: 0.0.0.0 | Host: 0.0.0.0 | ||||||
| Port: 9912 | Port: 9912 | ||||||
| Timeout: 15000 #服务超时时间 | Timeout: 150000 #服务超时时间 | ||||||
| SourceMysql: "fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest" | SourceMysql: "fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest" | ||||||
| Env: "test" | Env: "test" | ||||||
| Auth: | Auth: | ||||||
|  | |||||||
| @ -57,6 +57,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | |||||||
| 				Path:    "/api/upload/upload-file-base", | 				Path:    "/api/upload/upload-file-base", | ||||||
| 				Handler: UploadFileBaseHandler(serverCtx), | 				Handler: UploadFileBaseHandler(serverCtx), | ||||||
| 			}, | 			}, | ||||||
|  | 			{ | ||||||
|  | 				Method:  http.MethodPost, | ||||||
|  | 				Path:    "/api/upload/up-standard-logo", | ||||||
|  | 				Handler: UploadLogoStandardHandler(serverCtx), | ||||||
|  | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	) | 	) | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										35
									
								
								server/upload/internal/handler/uploadlogostandardhandler.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								server/upload/internal/handler/uploadlogostandardhandler.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | |||||||
|  | package handler | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"net/http" | ||||||
|  | 	"reflect" | ||||||
|  | 
 | ||||||
|  | 	"fusenapi/utils/basic" | ||||||
|  | 
 | ||||||
|  | 	"fusenapi/server/upload/internal/logic" | ||||||
|  | 	"fusenapi/server/upload/internal/svc" | ||||||
|  | 	"fusenapi/server/upload/internal/types" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func UploadLogoStandardHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||||||
|  | 	return func(w http.ResponseWriter, r *http.Request) { | ||||||
|  | 
 | ||||||
|  | 		var req types.UploadLogoStandardReq | ||||||
|  | 		userinfo, err := basic.RequestParse(w, r, svcCtx, &req) | ||||||
|  | 		if err != nil { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		// 创建一个业务逻辑层实例 | ||||||
|  | 		l := logic.NewUploadLogoStandardLogic(r.Context(), svcCtx) | ||||||
|  | 
 | ||||||
|  | 		rl := reflect.ValueOf(l) | ||||||
|  | 		basic.BeforeLogic(w, r, rl) | ||||||
|  | 
 | ||||||
|  | 		resp := l.UploadLogoStandard(&req, userinfo) | ||||||
|  | 
 | ||||||
|  | 		if !basic.AfterLogic(w, r, rl, resp) { | ||||||
|  | 			basic.NormalAfterLogic(w, r, resp) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -152,29 +152,29 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us | |||||||
| 
 | 
 | ||||||
| 	var headerData = make(map[string]string, 1) | 	var headerData = make(map[string]string, 1) | ||||||
| 	headerData["Content-Type"] = "application/json" | 	headerData["Content-Type"] = "application/json" | ||||||
| 	result, err := curl.ApiCall(l.svcCtx.Config.BLMService.ImageProcess.Url, "POST", headerData, strings.NewReader(string(postMapB)), time.Second*20) | 	result, err := curl.ApiCall(l.svcCtx.Config.BLMService.ImageProcess.Url, "POST", headerData, strings.NewReader(string(postMapB)), time.Minute*5) | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logx.Error(err) | 		logx.Error(err) | ||||||
| 		return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail") | 		return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 01") | ||||||
| 	} | 	} | ||||||
| 	defer result.Body.Close() | 	defer result.Body.Close() | ||||||
| 	b, err := io.ReadAll(result.Body) | 	b, err := io.ReadAll(result.Body) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logx.Error(err) | 		logx.Error(err) | ||||||
| 		return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail") | 		return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 02") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if string(b) == "Internal Server Error" { | 	if string(b) == "Internal Server Error" { | ||||||
| 		err = errors.New("BLMService fail Internal Server Error") | 		err = errors.New("BLMService fail Internal Server Error") | ||||||
| 		logx.Error(err) | 		logx.Error(err) | ||||||
| 		return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail") | 		return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 03") | ||||||
| 	} else { | 	} else { | ||||||
| 		var resData map[string]interface{} | 		var resData map[string]interface{} | ||||||
| 		err = json.Unmarshal(b, &resData) | 		err = json.Unmarshal(b, &resData) | ||||||
| 		if err != nil || resData == nil { | 		if err != nil || resData == nil { | ||||||
| 			logx.Error(err) | 			logx.Error(err) | ||||||
| 			return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail") | 			return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 04") | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if resData != nil { | 		if resData != nil { | ||||||
| @ -182,11 +182,11 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us | |||||||
| 				resultStr = resData["data"].(string) | 				resultStr = resData["data"].(string) | ||||||
| 			} else { | 			} else { | ||||||
| 				logx.Error(err) | 				logx.Error(err) | ||||||
| 				return resp.SetStatus(basic.CodeFileUploadLogoErrType, "service fail") | 				return resp.SetStatus(basic.CodeFileUploadLogoErrType, "service fail 05") | ||||||
| 			} | 			} | ||||||
| 		} else { | 		} else { | ||||||
| 			logx.Error(err) | 			logx.Error(err) | ||||||
| 			return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail") | 			return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 06") | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										43
									
								
								server/upload/internal/logic/uploadlogostandardlogic.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								server/upload/internal/logic/uploadlogostandardlogic.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,43 @@ | |||||||
|  | package logic | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"fusenapi/utils/auth" | ||||||
|  | 	"fusenapi/utils/basic" | ||||||
|  | 
 | ||||||
|  | 	"context" | ||||||
|  | 
 | ||||||
|  | 	"fusenapi/server/upload/internal/svc" | ||||||
|  | 	"fusenapi/server/upload/internal/types" | ||||||
|  | 
 | ||||||
|  | 	"github.com/zeromicro/go-zero/core/logx" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | type UploadLogoStandardLogic struct { | ||||||
|  | 	logx.Logger | ||||||
|  | 	ctx    context.Context | ||||||
|  | 	svcCtx *svc.ServiceContext | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func NewUploadLogoStandardLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogoStandardLogic { | ||||||
|  | 	return &UploadLogoStandardLogic{ | ||||||
|  | 		Logger: logx.WithContext(ctx), | ||||||
|  | 		ctx:    ctx, | ||||||
|  | 		svcCtx: svcCtx, | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // 处理进入前逻辑w,r | ||||||
|  | // func (l *UploadLogoStandardLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { | ||||||
|  | // } | ||||||
|  | 
 | ||||||
|  | // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 | ||||||
|  | // func (l *UploadLogoStandardLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { | ||||||
|  | // // httpx.OkJsonCtx(r.Context(), w, resp) | ||||||
|  | // } | ||||||
|  | 
 | ||||||
|  | func (l *UploadLogoStandardLogic) UploadLogoStandard(req *types.UploadLogoStandardReq, userinfo *auth.UserInfo) (resp *basic.Response) { | ||||||
|  | 	// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) | ||||||
|  | 	// userinfo 传入值时, 一定不为null | ||||||
|  | 
 | ||||||
|  | 	return resp.SetStatus(basic.CodeOK) | ||||||
|  | } | ||||||
| @ -5,6 +5,14 @@ import ( | |||||||
| 	"fusenapi/utils/basic" | 	"fusenapi/utils/basic" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | type UploadLogoStandardReq struct { | ||||||
|  | 	IsRemoveBg string `form:"is_remove_bg"` | ||||||
|  | 	LogoFile   string `form:"logo_file"` | ||||||
|  | 	Width      string `form:"width"` | ||||||
|  | 	Height     string `form:"height"` | ||||||
|  | 	Proportion int64  `form:"proportion"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
| type UploadFileBaseReq struct { | type UploadFileBaseReq struct { | ||||||
| 	ApiType      int64  `form:"api_type,options=[1,2],default=1"`      // 调用类型:1=对外,2=对内 | 	ApiType      int64  `form:"api_type,options=[1,2],default=1"`      // 调用类型:1=对外,2=对内 | ||||||
| 	FileKey      string `form:"file_key"`                              // 上传唯一标识信息 | 	FileKey      string `form:"file_key"`                              // 上传唯一标识信息 | ||||||
|  | |||||||
| @ -42,8 +42,21 @@ service upload { | |||||||
| 	@handler UploadFileBaseHandler | 	@handler UploadFileBaseHandler | ||||||
| 	post /api/upload/upload-file-base(UploadFileBaseReq) returns (response); | 	post /api/upload/upload-file-base(UploadFileBaseReq) returns (response); | ||||||
| 
 | 
 | ||||||
|  | 	@handler UploadLogoStandardHandler | ||||||
|  | 	post /api/upload/up-standard-logo(UploadLogoStandardReq) returns (response); | ||||||
|  | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | type ( | ||||||
|  | 	UploadLogoStandardReq { | ||||||
|  | 		IsRemoveBg string `form:"is_remove_bg"` | ||||||
|  | 		LogoFile   string `form:"logo_file"` | ||||||
|  | 		Width      string `form:"width"` | ||||||
|  | 		Height     string `form:"height"` | ||||||
|  | 		Proportion int64  `form:"proportion"` | ||||||
|  | 	} | ||||||
|  | ) | ||||||
|  | 
 | ||||||
| type ( | type ( | ||||||
| 	UploadFileBaseReq { | 	UploadFileBaseReq { | ||||||
| 		ApiType      int64  `form:"api_type,options=[1,2],default=1"`      // 调用类型:1=对外,2=对内 | 		ApiType      int64  `form:"api_type,options=[1,2],default=1"`      // 调用类型:1=对外,2=对内 | ||||||
|  | |||||||
| @ -37,6 +37,9 @@ type ( | |||||||
| 
 | 
 | ||||||
| 		// logo合图 | 		// logo合图 | ||||||
| 		LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) | 		LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) | ||||||
|  | 
 | ||||||
|  | 		// logo裁剪 | ||||||
|  | 		LogoStandard(ctx context.Context, in *LogoStandardReq) (*LogoStandardRes, error) | ||||||
| 	} | 	} | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| @ -225,3 +228,20 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* logo合图 */ | /* logo合图 */ | ||||||
|  | type ( | ||||||
|  | 	LogoStandardReq struct { | ||||||
|  | 		IsRemoveBg string `json:"is_remove_bg"` | ||||||
|  | 		LogoFile   string `json:"logo_file"` | ||||||
|  | 		Width      string `json:"width"` | ||||||
|  | 		Height     string `json:"height"` | ||||||
|  | 		Proportion int64  `json:"proportion"` | ||||||
|  | 	} | ||||||
|  | 	LogoStandardRes struct{} | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | /* 图片裁剪 */ | ||||||
|  | func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardReq) (*LogoStandardRes, error) { | ||||||
|  | 	return nil, nil | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /* 图片裁剪 */ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user