12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package logic
- import (
- "bp.jydev.jianyu360.cn/BaseService/biService/entity"
- "bp.jydev.jianyu360.cn/BaseService/biService/rpc/internal/svc"
- "bp.jydev.jianyu360.cn/BaseService/biService/rpc/pb"
- fpb "bp.jydev.jianyu360.cn/BaseService/fileCenter/rpc/pb"
- "context"
- "encoding/json"
- "github.com/zeromicro/go-zero/core/logx"
- "strings"
- )
- type UpFileLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewUpFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpFileLogic {
- return &UpFileLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- func (l *UpFileLogic) UpFile(in *pb.UpFileReq) (*pb.BiReply, error) {
- up, err := entity.FileCenterRpc.Upload(l.ctx, &fpb.UploadReq{
- File: in.File,
- OssBucketName: entity.OssBucketName,
- OssUrl: entity.OssUrl,
- Name: in.FileName,
- NeedEncryption: false,
- })
- if up == nil || up.Url == "" {
- return &pb.BiReply{
- ErrorCode: 1,
- ErrorMsg: "文件上传失败",
- Data: nil,
- }, err
- }
- key := up.Key
- fileTypeTmp := strings.Split(in.FileName, ".")
- var ftype string
- if len(fileTypeTmp) > 0 && len(fileTypeTmp) == 2 {
- ftype = strings.Split(in.FileName, ".")[1]
- }
- data := map[string]interface{}{
- "filename": in.FileName,
- "ftype": ftype,
- "fid": key,
- "size": in.FileSize,
- "ossurl": entity.OssUrl,
- "url": up.Url,
- }
- dataByte, _ := json.Marshal(data)
- return &pb.BiReply{
- ErrorCode: 0,
- ErrorMsg: "",
- Data: dataByte,
- }, nil
- }
|