1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package logic
- import (
- IC "app.yhyue.com/moapp/jyInfo/rpc/consumer/init"
- model "app.yhyue.com/moapp/jyInfo/rpc/model/oss"
- "bytes"
- "context"
- "strings"
- "time"
- "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumerclient"
- "app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
- mc "app.yhyue.com/moapp/jybase/common"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type InfoFileUploadLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewInfoFileUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoFileUploadLogic {
- return &InfoFileUploadLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // 上传附件
- func (l *InfoFileUploadLogic) InfoFileUpload(in *consumerclient.InfoFileUploadReq) (*consumerclient.InfoFileUploadResp, error) {
- var resp consumerclient.InfoFileUploadResp
- //model.InitOss()
- key := model.GetHashKey(in.File) + model.TypeByExt(in.FileName)
- t1 := time.Now()
- b, err := model.OssPutObject(key, bytes.NewReader(in.File), mc.InterfaceToStr(IC.C.Oss.OssBucketName))
- logx.Info("----------", time.Since(t1))
- fileSize := mc.InterfaceToStr(in.FileSize/1024) + "KB"
- if err == nil && b {
- var data consumerclient.InfoFileUploadData
- data.Filename = in.FileName
- data.Size = fileSize
- data.Fid = key
- data.Ossurl = IC.C.Oss.OssUrl
- ftypes := strings.Split(in.FileName, ".")
- var ftype string
- if len(ftypes) > 0 && len(ftypes) == 2 {
- ftype = strings.Split(in.FileName, ".")[1]
- }
- data.Ftype = ftype
- resp.Data = &data
- return &resp, err
- }
- resp.ErrCode = -1
- resp.ErrMsg = "上传失败"
- return &resp, nil
- }
|